﻿using System;
using System.IO;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;

using CE.Mail;
using CE.User;
using CE.Global;
using CE.Security;
using CE.InputOut;
using CE.Database;
using CE.CarInsurance;
using CXDecryption;

public partial class carinsurance_garage_SearchGarage : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }
        if (!IsPostBack)
        {
            ddlApplicationType.Items.Clear();
            ddlApplicationType.Items.Clear();
            ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeNew, "NEW"));
            ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeChangeBroker, "CHB"));
            lblNonGGStatus.Text = "0";
            lblPayError.Text = "";
            lblOnlinePayError.Text = "";
            divCar.Visible = false;
            lblSearchMessage.Text = "";
            pnlCarDetails.Visible = false;
            txtCarId.Text = "";
            txtLastQuoteRefNo.Text = "";
            txtLastStep.Text = "";
            LoadOption();
            LoadGarageType();
            LoadInsuranceType();
            LoadVehicleType();
            LoadOccupation();
            LoadDOB();
            LoadCommanceDate();
            LoadCardExpiryMonth();
            LoadCardExpiryYear();
            LoadFileUploadType();

            btnPaySubmit.Enabled = true;
            btnPayNew.Enabled = true;

            chkApprove.Enabled = false;
            chkRefund.Enabled = false;

            lblLoadMessage.Text = string.Empty;

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
            ddlApplicationType_SelectedIndexChanged(null, null);
            if (Request.QueryString["refno"] != null)
            {
                txtSearch.Text = Request.QueryString["refno"].ToString();
                btnSearch_Click(sender, e);


            }


            LoadProvider();
            LoadCarMake();
            LoadRegion();
            LoadProvince();
        }
    }

    private DataTable CheckCarId(string strCarId)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable();
        string strSql = "SELECT CarId, RefCEUserId FROM tblCarDetailTH WHERE [Status] = 1 AND CarId = " + strCarId;
        _dt = _db.GetDataTable(strSql);
        _db = null;
        return _dt;

    }

    private string GetLastYearRefNo(string strCarID, string strCustomerID)
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT Info7 FROM tblCarPolicy WHERE Info7 IS NOT NULL AND LEN(Info7) > 0 AND CECarId = " + strCarID + " And RefCEUserID = " + strCustomerID;
        string _lastYearRefNo = string.Empty;
        object _objLastYearRefNo = _db.ExecuteScalarSqlStatement(strSql);

        if (_objLastYearRefNo != null)
        {
            _lastYearRefNo = _objLastYearRefNo.ToString();
        }

        _db = null;
        _objLastYearRefNo = null;

        return _lastYearRefNo;

    }

    private string GetLastYearPolicyNo(string strCarId, string strCustomerId)
    {
        MyDatabase _db = new MyDatabase();
        string strSql = "SELECT Remarks FROM tblNonGGTransaction ";
        strSql += " WHERE TransactionTypeId = 300 AND CECarId = " + strCarId + " AND RefCEUserId = " + strCustomerId;
        string _lastYearPolicyNo = string.Empty;
        object _objLastYearPolicyNo = _db.ExecuteScalarSqlStatement(strSql);

        if (_objLastYearPolicyNo != null)
        {
            _lastYearPolicyNo = _objLastYearPolicyNo.ToString();
        }

        _db = null;
        _objLastYearPolicyNo = null;

        return _lastYearPolicyNo;

    }

    protected void btnAppSummary_Click(object sender, EventArgs e)
    {
        Response.Redirect("ApplicationStatus.aspx?search=" + lblUpRefNo.Text);
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        lblNonGGStatus.Text = "0";
        pnlOptionMessage.Visible = false;
        lblOptionError.Text = string.Empty;
        lblOptionMessage.Text = string.Empty;
        pnlDetails.Visible = false;
        pnlPayment.Visible = false;
        pnlCarDetails.Visible = false;
        pnlApplicationCancel.Visible = false;
        pnlApplicationRetrieve.Visible = false;
        pnlUploadFileList.Visible = false;
        LoadOption();
        if (Server.HtmlEncode(txtSearch.Text).Trim() != "" && Server.HtmlEncode(txtSearch.Text).Trim().Length > 4)
        {
            if (CheckSelectedItem(Server.HtmlEncode(txtSearch.Text).Trim().ToUpper()))
            {
                txtCarId.Text = CE.Global.General.GetCarId(Server.HtmlEncode(txtSearch.Text).Trim());
                DataTable _dtCarCustomer = new DataTable();
                _dtCarCustomer = CheckCarId(txtCarId.Text);
                if (_dtCarCustomer != null && _dtCarCustomer.Rows.Count > 0)
                {
                    txtCarId.Text = _dtCarCustomer.Rows[0]["CarId"].ToString();
                    txtUserId.Text = _dtCarCustomer.Rows[0]["RefCEUserId"].ToString();
                }
                if (txtCarId.Text != string.Empty && txtUserId.Text != string.Empty && txtCarId.Text != "0" && txtUserId.Text != "0")
                {
                    LoadApplicationDetails();

                    

                    lblMailingStatus.Text = "0";
                    if (!CheckApplicationProcessStatus(lblUpRefNo.Text.Trim().ToUpper(), "MAILING"))
                    {
                        lblMailingStatus.Text = "1";
                    }
                }
                else
                {
                    lblSearchMessage.Text = Resources.General.CheckRefNo;
                    divCar.Visible = false;
                }
            }
            else
            {
                lblSearchMessage.Text = Resources.General.CheckRefNo;
                divCar.Visible = false;
            }
        }
        else if (Server.HtmlEncode(txtSearch.Text).Trim().Length > 1 && Server.HtmlEncode(txtSearch.Text).Trim().Length <= 4)
        {
            lblSearchMessage.Text = Resources.General.CheckRefNo;
            divCar.Visible = false;
        }
        lblLoadMessage.Text = string.Empty;
    }

    private void LoadDate()
    {
        Int32 intStartYear = dateTimeNow.Year - 50;
        Int32 intEndYear = dateTimeNow.Year + 50;
        if (intStartYear == 0) intStartYear = dateTimeNow.Year - 75;
        if (intEndYear == 0) intEndYear = dateTimeNow.Year + 20;

        ddlCommenceYear.Items.Clear();

        for (int i = intEndYear; i >= intStartYear; i--)
        {
            if (lblLangOption.Text == "1")
            {
                ddlCommenceYear.Items.Add(new ListItem((i + 543).ToString(), i.ToString()));
            }
            else if (lblLangOption.Text == "2")
            {
                ddlCommenceYear.Items.Add(i.ToString());
            }
        }
        lblLoadMessage.Text = string.Empty;
    }

    private void LoadOption()
    {
        if (Session[CE.Global.General.UserRole] != null)
        {
            if (Session[CE.Global.General.UserRole].ToString() == "100")
            {
                ddlOption.Items.Clear();
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.MoreDetails, "EDIT"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Payment, "PAYM"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.CancelRejectApplication, "ACNL"));
                ddlOption.SelectedIndex = 0;
            }
            else if (Session[CE.Global.General.UserRole].ToString() == "200")
            {
                ddlOption.Items.Clear();
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.MoreDetails, "EDIT"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Payment, "PAYM"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.UploadFile, "UPLD"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.CancelRejectApplication, "ACNL"));
                ddlOption.SelectedIndex = 0;
            }
            else
            {
                ddlOption.Items.Clear();
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.MoreDetails, "EDIT"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Payment, "PAYM"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.UploadFile, "UPLD"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.CancelRejectApplication, "ACNL"));
                ddlOption.SelectedIndex = 0;
            }
            lblLoadMessage.Text = string.Empty;
        }

    }

    public void LoadApplicationDetails()
    {
        ClearFields();
        if (txtLastQuoteRefNo.Text != txtSearch.Text)
        {
            txtLastStep.Text = "";
            txtLastQuoteRefNo.Text = "";
        }
        lblNonGGStatus.Text = "0";
        string _ProviderRefCode = txtSearch.Text.Trim();
        _ProviderRefCode = _ProviderRefCode.Substring(0, 3);
        DataSet _dsApplication = new DataSet();
        NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
        
        _dsApplication = _nonggpackagedb.GetCarDetails(Convert.ToInt64(txtCarId.Text.Trim()), Convert.ToInt64(txtUserId.Text.Trim()));
        if (_dsApplication != null && _dsApplication.Tables.Count > 0 && _dsApplication.Tables[0].Rows.Count > 0)
        {
            if (_dsApplication != null && _dsApplication.Tables.Count > 2 && _dsApplication.Tables[2].Rows.Count > 0)
            {
                DateTime _LastUpdateDate = new DateTime();
                _LastUpdateDate = Convert.ToDateTime(_dsApplication.Tables[2].Rows[0]["ModifiedDate"].ToString());
                lblLastUpdate.Text = Resources.General.LastUpdated + " : " + _LastUpdateDate.ToString("dd/MMM/yyyy hh:mm tt");
            }
            else
            {
                lblLastUpdate.Text = Resources.General.HaveNotSubmit;
            }

            lblSearchMessage.Text = "";
            if (_dsApplication != null && _dsApplication.Tables.Count > 2 && _dsApplication.Tables[2].Rows.Count > 0)
            {
                divCar.Visible = true;
                LoadNonGGApplicationDetails(_dsApplication);
            }
            else if (_dsApplication != null && _dsApplication.Tables.Count > 2 && _dsApplication.Tables[2].Rows.Count == 0)
            {
                #region Assign Values
                if (_dsApplication.Tables[0].Rows[0]["CXBrokerProviderId"].ToString() == CE.Global.General.GetProviderId(_ProviderRefCode))
                {
                    divCar.Visible = true;
                    ddlCustomerType.SelectedIndex = 0;

                    if (_dsApplication.Tables[0].Rows[0]["Info7"] != DBNull.Value && _dsApplication.Tables[0].Rows[0]["Info7"].ToString() != string.Empty)
                    {
                        if (_dsApplication.Tables[0].Rows[0]["Info6"] != DBNull.Value && _dsApplication.Tables[0].Rows[0]["Info6"].ToString() != string.Empty)
                        {
                            txtLastYearCarId.Text = _dsApplication.Tables[0].Rows[0]["Info6"].ToString();
                        }
                        lblLastYearRefNo.Text = _dsApplication.Tables[0].Rows[0]["Info7"].ToString();
                        txtLastYearRefNo.Text = lblLastYearRefNo.Text;

                        lblLastYearPolicyNo.Text = string.Empty;
                        if (txtLastYearRefNo.Text.Trim().Length > 0)
                        {
                            lblRenewalMessage.Text = "Renewal App Details. Last Year Ref.No [ " + txtLastYearRefNo.Text + " ]";
                            ClientScript.RegisterStartupScript(lblLastUpdate.GetType(), "DownloadPremiumAlert", "alert('" + lblRenewalMessage.Text + "!');", true);


                            string _LstYrProviderRefCode = txtLastYearRefNo.Text.Trim();
                            _LstYrProviderRefCode = _LstYrProviderRefCode.Substring(0, 3);
                            if (CE.Global.General.GetProviderId(_ProviderRefCode) == CE.Global.General.GetProviderId(_LstYrProviderRefCode))
                            {
                                ddlApplicationType.Items.Clear();
                                ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeRenewalSameInsurer, "REN"));
                                ddlApplicationType.Text = "REN";
                                ddlApplicationType_SelectedIndexChanged(null, null);
                                lblLastYearPolicyNo.Text = GetLastYearPolicyNo(txtLastYearCarId.Text, txtUserId.Text);
                                txtLastYearPolicyNo.Text = lblLastYearPolicyNo.Text;
                            }
                            else
                            {
                                ddlApplicationType.Items.Clear();
                                ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeRenewalOtherInsurer, "RNO"));
                                ddlApplicationType.Text = "RNO";
                                ddlApplicationType_SelectedIndexChanged(null, null);
                            }
                        }
                        else
                        {
                            ddlApplicationType.Items.Clear();
                            ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeNew, "NEW"));
                            ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeChangeBroker, "CHB"));
                        }
                    }

                    if (_dsApplication != null && _dsApplication.Tables.Count > 4 && _dsApplication.Tables[4].Rows.Count > 0)
                    {
                        if (_dsApplication.Tables[4].Rows[0]["Name"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["Name"].ToString() != string.Empty)
                        {
                            txtCustomerName.Text = _dsApplication.Tables[4].Rows[0]["Name"].ToString();
                        }
                        else
                        {
                            txtCustomerName.Text = _dsApplication.Tables[0].Rows[0]["InsuredPerson"].ToString();
                        }
                    }
                    else
                    {
                        txtCustomerName.Text = _dsApplication.Tables[0].Rows[0]["InsuredPerson"].ToString();
                    }
                    lblUpApplicantName.Text = _dsApplication.Tables[0].Rows[0]["InsuredPerson"].ToString();
                    txtInsuredPerson.Text = _dsApplication.Tables[0].Rows[0]["InsuredPerson"].ToString();
                    txtContactNumber.Text = _dsApplication.Tables[0].Rows[0]["Mobile"].ToString();
                    txtProviderId.Text = _dsApplication.Tables[0].Rows[0]["CXBrokerProviderId"].ToString();
                    txtNewQuoteRefNo.Text = CE.Global.General.GetReferenceNumber(txtCarId.Text.Trim(), txtProviderId.Text.Trim());
                    
                    txtUserId.Text = _dsApplication.Tables[0].Rows[0]["RefCEUserId"].ToString();
                    txtCarModelYear.Text = _dsApplication.Tables[0].Rows[0]["ManufactYear"].ToString();
                    txtCarMakeModel.Text = _dsApplication.Tables[0].Rows[0]["MakeModelDesc"].ToString();
                    if (_dsApplication.Tables[0].Rows[0]["InsuranceType"] != DBNull.Value)
                    {
                        ddlInsuranceType.Text = _dsApplication.Tables[0].Rows[0]["InsuranceType"].ToString();
                    }
                    if (_dsApplication.Tables[0].Rows[0]["VehicleType"] != DBNull.Value)
                    {
                        ddlVehicleType.Text = _dsApplication.Tables[0].Rows[0]["VehicleType"].ToString();
                    }
                    if (_dsApplication.Tables[0].Rows[0]["GarageType"] != DBNull.Value)
                    {
                        ddlGarageType.Text = _dsApplication.Tables[0].Rows[0]["GarageType"].ToString();
                    }
                    ddlNCB.Text = _dsApplication.Tables[0].Rows[0]["NCDPercent"].ToString();
                    
                    string _sumInsured = string.Empty;
                    _sumInsured = _dsApplication.Tables[0].Rows[0]["SumInsured"].ToString();
                    decimal _outSumInsurred = 0;
                    if (!decimal.TryParse(_sumInsured, out _outSumInsurred))
                    {
                        _sumInsured = "0";
                    }
                    else
                    {
                        _sumInsured = _outSumInsurred.ToString("#0");
                    }
                    txtSumInsured.Text = _sumInsured.ToString();// _dsApplication.Tables[0].Rows[0]["SumInsured"].ToString();
                    txtInsurancePremium.Text = _dsApplication.Tables[0].Rows[0]["Premium"].ToString();
                    txtTotalPremium.Text = _dsApplication.Tables[0].Rows[0]["TotalPremium"].ToString();
                    txtCollectedAmount.Text = _dsApplication.Tables[0].Rows[0]["FinalAnnualPremium"].ToString();
                    txtCTPL.Text = _dsApplication.Tables[0].Rows[0]["CTPL"].ToString();
                    txtCurrentInsurer.Text = _dsApplication.Tables[0].Rows[0]["CurrentInsurer"].ToString();
                    txtPlateNumber.Text = _dsApplication.Tables[0].Rows[0]["CarPlate"].ToString();
                    
                    if (_dsApplication.Tables[0].Rows[0]["IsCTPL"].ToString() == "False" || _dsApplication.Tables[0].Rows[0]["IsCTPL"].ToString() == "0")
                    {
                        ddlCTPL.Text = "0";
                    }
                    else
                    {
                        ddlCTPL.Text = "1";
                    }
                    
                    if (_dsApplication.Tables[0].Rows[0]["Gender"] != DBNull.Value)
                    {
                        ddlGender.Text = _dsApplication.Tables[0].Rows[0]["Gender"].ToString();
                    }
                    if (_dsApplication.Tables[0].Rows[0]["OccupationId"] != DBNull.Value)
                    {
                        ddlOccupation.Text = _dsApplication.Tables[0].Rows[0]["OccupationId"].ToString();
                    }
                    txtInsuranceCompany.Text = _dsApplication.Tables[0].Rows[0]["CompanyName"].ToString();
                    txtPackage.Text = _dsApplication.Tables[0].Rows[0]["Package"].ToString();
                    ddlNamedDriver.Text = _dsApplication.Tables[0].Rows[0]["NoOfDriver"].ToString();
                    ddlNamedDriver_SelectedIndexChanged(null, null);
                    txtDriverId1.Text = "0";
                    txtDriverId2.Text = "0";
                    DateTime Commdate = dateTimeNow;
                    if (_dsApplication.Tables[0].Rows[0]["CoverageCommenceDate"] != DBNull.Value && _dsApplication.Tables[0].Rows[0]["CoverageCommenceDate"].ToString() != string.Empty)
                    {
                        Commdate = Convert.ToDateTime(_dsApplication.Tables[0].Rows[0]["CoverageCommenceDate"].ToString());
                    }
                    AssignDate(Commdate.Day, ddlCommenceDay);
                    AssignMonth(Commdate.Month, ddlCommenceMonth);
                    AssignYear(Commdate.Year, ddlCommenceYear);

                    AssignDate(Commdate.Day, ddlPolicyDay);
                    AssignMonth(Commdate.Month, ddlPolicyMonth);
                    AssignYear(Commdate.Year, ddlPolicyYear);

                    DateTime DOB = dateTimeNow;
                    if (_dsApplication.Tables[0].Rows[0]["DOB"] != DBNull.Value && _dsApplication.Tables[0].Rows[0]["DOB"].ToString() != string.Empty)
                    {
                        DOB = Convert.ToDateTime(_dsApplication.Tables[0].Rows[0]["DOB"].ToString());
                    }
                    AssignDate(DOB.Day, ddlDOBDay);
                    AssignMonth(DOB.Month, ddlDOBMonth);
                    AssignYear(DOB.Year, ddlDOBYear);
                    DateTime DriverDOB1 = dateTimeNow.AddYears(-20);
                    DateTime DriverDOB2 = dateTimeNow.AddYears(-20);
                    if (_dsApplication.Tables.Count > 1)
                    {
                        if (_dsApplication.Tables[1].Rows.Count > 0 && _dsApplication.Tables[1].Rows[0]["DOB"] != DBNull.Value && _dsApplication.Tables[1].Rows[0]["DOB"].ToString() != string.Empty)
                        {
                            DriverDOB1 = Convert.ToDateTime(_dsApplication.Tables[1].Rows[0]["DOB"].ToString());
                        }
                        if (_dsApplication.Tables[1].Rows.Count > 1 && _dsApplication.Tables[1].Rows[1]["DOB"] != DBNull.Value && _dsApplication.Tables[1].Rows[1]["DOB"].ToString() != string.Empty)
                        {
                            DriverDOB2 = Convert.ToDateTime(_dsApplication.Tables[1].Rows[1]["DOB"].ToString());
                        }
                    }
                    AssignDate(DriverDOB1.Day, ddlDriver1DOBDay);
                    AssignMonth(DriverDOB1.Month, ddlDriver1DOBMonth);
                    AssignYear(DriverDOB1.Year, ddlDriver1DOBYear);
                    AssignDate(DriverDOB2.Day, ddlDriver2DOBDay);
                    AssignMonth(DriverDOB2.Month, ddlDriver2DOBMonth);
                    AssignYear(DriverDOB2.Year, ddlDriver2DOBYear);
                    if (ddlNamedDriver.Text == "0")
                    {
                        rfvDriverFirst.Enabled = false;
                        revDriverFirst.Enabled = false;
                        rfvDriver1IDNo.Enabled = false;
                        rfvDriver1LicenseNo.Enabled = false;
                        rfvDriverTwo.Enabled = false;
                        revDriverTwo.Enabled = false;
                        rfvDriver2IDNo.Enabled = false;
                        rfvDriver2LicenseNo.Enabled = false;
                    }
                    if (ddlNamedDriver.Text == "1")
                    {
                        rfvDriverFirst.Enabled = true;
                        revDriverFirst.Enabled = true;
                        rfvDriver1IDNo.Enabled = true;
                        rfvDriver1LicenseNo.Enabled = true;
                        rfvDriverTwo.Enabled = false;
                        revDriverTwo.Enabled = false;
                        rfvDriver2IDNo.Enabled = false;
                        rfvDriver2LicenseNo.Enabled = false;
                    }
                    if (ddlNamedDriver.Text == "2")
                    {
                        rfvDriverFirst.Enabled = true;
                        revDriverFirst.Enabled = true;
                        rfvDriver1IDNo.Enabled = true;
                        rfvDriver1LicenseNo.Enabled = true;
                        rfvDriverTwo.Enabled = true;
                        revDriverTwo.Enabled = true;
                        rfvDriver2IDNo.Enabled = true;
                        rfvDriver2LicenseNo.Enabled = true;
                    }
                    if (_dsApplication.Tables.Count > 4 && _dsApplication.Tables[4].Rows.Count > 0)
                    {
                        if (_dsApplication.Tables[4].Rows[0]["Name"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["Name"].ToString() != string.Empty)
                        {
                            txtCustomerName.Text = _dsApplication.Tables[4].Rows[0]["Name"].ToString();
                        }
                        if (_dsApplication.Tables[4].Rows[0]["BeneficiaryName"] != DBNull.Value)
                            txtBeneficiary.Text = _dsApplication.Tables[4].Rows[0]["BeneficiaryName"].ToString();
                        if (_dsApplication.Tables[4].Rows[0]["IsMailingAddressDiff"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["IsMailingAddressDiff"].ToString() != string.Empty
                            && _dsApplication.Tables[4].Rows[0]["IsMailingAddressDiff"].ToString() != "true" && _dsApplication.Tables[4].Rows[0]["IsMailingAddressDiff"].ToString() != "1")
                        {
                            txtCurrentAddress.Text = _dsApplication.Tables[4].Rows[0]["PresentAddress"].ToString();
                            txtSubDistrict.Text = _dsApplication.Tables[4].Rows[0]["SubDistrict"].ToString();
                            txtStateProvince.Text = _dsApplication.Tables[4].Rows[0]["District"].ToString();
                            txtProvince.Text = _dsApplication.Tables[4].Rows[0]["Province"].ToString();
                            txtPostalCode.Text = _dsApplication.Tables[4].Rows[0]["PostalCode"].ToString();
                        }
                        else
                        {
                            txtCurrentAddress.Text = _dsApplication.Tables[4].Rows[0]["MailingAddress"].ToString();
                            txtSubDistrict.Text = _dsApplication.Tables[4].Rows[0]["MailingSubDistrict"].ToString();
                            txtStateProvince.Text = _dsApplication.Tables[4].Rows[0]["MailingDistrict"].ToString();
                            txtProvince.Text = _dsApplication.Tables[4].Rows[0]["MailingProvince"].ToString();
                            txtPostalCode.Text = _dsApplication.Tables[4].Rows[0]["MailingPostalCode"].ToString();
                        }
                        if (_dsApplication.Tables.Count > 5 && _dsApplication.Tables[5].Rows.Count > 0)
                        {
                            txtPackage.Text = _dsApplication.Tables[5].Rows[0]["CoverTypeDesc"].ToString();
                        }
                        if (_dsApplication.Tables[4].Rows[0]["EngineNumber"] != DBNull.Value)
                            txtEngineNumber.Text = _dsApplication.Tables[4].Rows[0]["EngineNumber"].ToString();
                        if (_dsApplication.Tables[4].Rows[0]["ChassisNumber"] != DBNull.Value)
                            txtChassisNumber.Text = _dsApplication.Tables[4].Rows[0]["ChassisNumber"].ToString();
                        if (_dsApplication.Tables[4].Rows[0]["CarPlate"] != DBNull.Value)
                            txtPlateNumber.Text = _dsApplication.Tables[4].Rows[0]["CarPlate"].ToString().ToUpper();
                        if (_dsApplication.Tables[4].Rows[0]["CarPlateProvince"] != DBNull.Value)
                            txtRegistrationProvince.Text = _dsApplication.Tables[4].Rows[0]["CarPlateProvince"].ToString();

                        DateTime _CreateDate = Convert.ToDateTime(_dsApplication.Tables[4].Rows[0]["CreatedDate"].ToString());
                        if (ddlApplicationDay.Items.Count > 0)
                            ddlApplicationDay.Items.Clear();
                        ddlApplicationDay.Items.Add(new ListItem(_CreateDate.Day.ToString("00"), _CreateDate.Day.ToString("00")));
                        if (ddlApplicationMonth.Items.Count > 0)
                            ddlApplicationMonth.Items.Clear();
                        ddlApplicationMonth.Items.Add(new ListItem(_CreateDate.Month.ToString("00"), _CreateDate.Month.ToString("00")));
                        if (ddlApplicationYear.Items.Count > 0)
                            ddlApplicationYear.Items.Clear();
                        ddlApplicationYear.Items.Add(new ListItem(_CreateDate.Year.ToString("0000"), _CreateDate.Year.ToString("0000")));
                    }
                    else
                    {
                        DateTime _CreateDate = Convert.ToDateTime(_dsApplication.Tables[0].Rows[0]["CreatedDate"].ToString());
                        if (ddlApplicationDay.Items.Count > 0)
                            ddlApplicationDay.Items.Clear();
                        ddlApplicationDay.Items.Add(new ListItem(_CreateDate.Day.ToString("00"), _CreateDate.Day.ToString("00")));
                        if (ddlApplicationMonth.Items.Count > 0)
                            ddlApplicationMonth.Items.Clear();
                        ddlApplicationMonth.Items.Add(new ListItem(_CreateDate.Month.ToString("00"), _CreateDate.Month.ToString("00")));
                        if (ddlApplicationYear.Items.Count > 0)
                            ddlApplicationYear.Items.Clear();
                        ddlApplicationYear.Items.Add(new ListItem(_CreateDate.Year.ToString("0000"), _CreateDate.Year.ToString("0000")));
                    }
                    
                }
                #endregion
            }
            else
            {
                lblSearchMessage.Text = Resources.General.CheckRefNo;
                divCar.Visible = false;
            }
            LoadLastYearApplicationDetails();
        }
        else
        {
            lblSearchMessage.Text = Resources.General.CheckRefNo;
            divCar.Visible = false;
        }
        if (txtUserId.Text != "" && txtProviderId.Text != "")
        {
            GetCarMoreDetails();
        }
    }

    public void LoadNonGGApplicationDetails(DataSet dsApplication)
    {
        ClearFields();
        string _ProviderRefCode = txtSearch.Text.Trim();
        _ProviderRefCode = _ProviderRefCode.Substring(0, 3);
        if (dsApplication != null && dsApplication.Tables.Count > 2 && dsApplication.Tables[2].Rows.Count > 0)
        {
            lblSearchMessage.Text = "";
            lblNonGGStatus.Text = "1";
            #region Assign Values
            
            lblAgentId.Text = "0";
            lblAdminId.Text = "0";
            if (dsApplication.Tables[0].Rows[0]["Info7"] != DBNull.Value && dsApplication.Tables[0].Rows[0]["Info7"].ToString() != string.Empty)
            {
                lblLastYearRefNo.Text = dsApplication.Tables[0].Rows[0]["Info7"].ToString();
                txtLastYearRefNo.Text = lblLastYearRefNo.Text;
                if (txtLastYearRefNo.Text.Trim().Length > 0)
                {
                    lblRenewalMessage.Text = "Renewal App Details. Last Year Ref.No [ " + txtLastYearRefNo.Text + " ]";
                    ClientScript.RegisterStartupScript(lblLastUpdate.GetType(), "DownloadPremiumAlert", "alert('" + lblRenewalMessage.Text + "!');", true);
                }
            }
            if (dsApplication.Tables[2].Rows[0]["Info1"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["Info1"].ToString() != string.Empty)
            {
                if (dsApplication.Tables[2].Rows[0]["Info1"].ToString().ToUpper() == "REN")
                {
                    ddlApplicationType.Items.Clear();
                    ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeRenewalSameInsurer, "REN"));
                    ddlApplicationType.Text = dsApplication.Tables[2].Rows[0]["Info1"].ToString();
                    ddlApplicationType_SelectedIndexChanged(null, null);
                }
                else if (dsApplication.Tables[2].Rows[0]["Info1"].ToString().ToUpper() == "RNO")
                {
                    ddlApplicationType.Items.Clear();
                    ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeRenewalOtherInsurer, "RNO"));
                    ddlApplicationType.Text = dsApplication.Tables[2].Rows[0]["Info1"].ToString();
                    ddlApplicationType_SelectedIndexChanged(null, null);
                }
                else
                {
                    ddlApplicationType.Items.Clear();
                    ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeNew, "NEW"));
                    ddlApplicationType.Items.Add(new ListItem(Resources.Proposal.AppTypeChangeBroker, "CHB"));
                    ddlApplicationType.Text = dsApplication.Tables[2].Rows[0]["Info1"].ToString();
                    ddlApplicationType_SelectedIndexChanged(null, null);
                }
            }
            if (dsApplication.Tables[2].Rows[0]["Info2"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["Info2"].ToString() != string.Empty)
            {
                txtLastYearPolicyNo.Text = dsApplication.Tables[2].Rows[0]["Info2"].ToString();
                lblLastYearPolicyNo.Text = dsApplication.Tables[2].Rows[0]["Info2"].ToString();
            }


            if (dsApplication.Tables[2].Rows[0]["AgentId"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["AgentId"].ToString() != string.Empty)
            {
                lblAgentId.Text = dsApplication.Tables[2].Rows[0]["AgentId"].ToString();
            }
            if (dsApplication.Tables[2].Rows[0]["AdminId"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["AdminId"].ToString() != string.Empty)
            {
                lblAdminId.Text = dsApplication.Tables[2].Rows[0]["AdminId"].ToString();
            }
            txtCarModelYear.Text = dsApplication.Tables[2].Rows[0]["CarYear"].ToString();
            txtCarMakeModel.Text = dsApplication.Tables[2].Rows[0]["CarModel"].ToString();
            if (dsApplication.Tables[2].Rows[0]["InsuranceType"] != DBNull.Value)
            {
                ddlInsuranceType.Text = dsApplication.Tables[2].Rows[0]["InsuranceType"].ToString();
            }
            if (dsApplication.Tables[2].Rows[0]["VehicleType"] != DBNull.Value)
            {
                ddlVehicleType.Text = dsApplication.Tables[2].Rows[0]["VehicleType"].ToString();
            }
            if (dsApplication.Tables[2].Rows[0]["GarageType"] != DBNull.Value)
            {
                ddlGarageType.Text = dsApplication.Tables[2].Rows[0]["GarageType"].ToString();
            }
            DateTime Commdate = dateTimeNow;
            if (dsApplication.Tables[2].Rows[0]["CoverageStart"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["CoverageStart"].ToString() != string.Empty)
            {
                Commdate = Convert.ToDateTime(dsApplication.Tables[2].Rows[0]["CoverageStart"].ToString());
            }
            AssignDate(Commdate.Day, ddlCommenceDay);
            AssignMonth(Commdate.Month, ddlCommenceMonth);
            AssignYear(Commdate.Year, ddlCommenceYear);
            DateTime policy = dateTimeNow;
            if (dsApplication.Tables[2].Rows[0]["CTPLStart"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["CTPLStart"].ToString() != string.Empty)
            {
                policy = Convert.ToDateTime(dsApplication.Tables[2].Rows[0]["CTPLStart"].ToString());
            }
            AssignDate(policy.Day, ddlPolicyDay);
            AssignMonth(policy.Month, ddlPolicyMonth);
            AssignYear(policy.Year, ddlPolicyYear);


            
            string _sumInsured = string.Empty;
            _sumInsured = dsApplication.Tables[2].Rows[0]["SumInsured"].ToString();
            decimal _outSumInsurred = 0;
            if (!decimal.TryParse(_sumInsured, out _outSumInsurred))
            {
                _sumInsured = "0";
            }
            else
            {
                _sumInsured = _outSumInsurred.ToString("#");
            }
            txtSumInsured.Text = _sumInsured.ToString();// dsApplication.Tables[2].Rows[0]["SumInsured"].ToString();
            txtInsurancePremium.Text = dsApplication.Tables[2].Rows[0]["Premium"].ToString();
            txtTotalPremium.Text = dsApplication.Tables[2].Rows[0]["TotalPremium"].ToString();
            txtCollectedAmount.Text = dsApplication.Tables[2].Rows[0]["FinalAnnualPremium"].ToString();
            txtCTPL.Text = dsApplication.Tables[2].Rows[0]["CTPL"].ToString();
            txtCurrentInsurer.Text = dsApplication.Tables[2].Rows[0]["CurrentInsurer"].ToString();
            
            if (dsApplication.Tables[2].Rows[0]["IsCTPL"].ToString() == "False" || dsApplication.Tables[2].Rows[0]["IsCTPL"].ToString() == "false" || dsApplication.Tables[2].Rows[0]["IsCTPL"].ToString() == "0")
            {
                ddlCTPL.Text = "0";
            }
            else
            {
                ddlCTPL.Text = "1";
            }
            
            txtInsuranceCompany.Text = dsApplication.Tables[0].Rows[0]["CompanyName"].ToString();
           
            txtEngineNumber.Text = dsApplication.Tables[2].Rows[0]["EngineNumber"].ToString();
            txtChassisNumber.Text = dsApplication.Tables[2].Rows[0]["ChassisNumber"].ToString();
            txtPlateNumber.Text = dsApplication.Tables[2].Rows[0]["CarPlate"].ToString();
            txtRegistrationProvince.Text = dsApplication.Tables[2].Rows[0]["CarPlateProvince"].ToString();
            ddlNCB.Text = dsApplication.Tables[2].Rows[0]["NCB"].ToString();

            
            txtProviderId.Text = dsApplication.Tables[0].Rows[0]["CXBrokerProviderId"].ToString();
            txtNewQuoteRefNo.Text = dsApplication.Tables[2].Rows[0]["QuoteRefNo"].ToString();
            txtUserId.Text = dsApplication.Tables[2].Rows[0]["RefCEUserId"].ToString();

            ddlCustomerType.Text = dsApplication.Tables[2].Rows[0]["CustomerType"].ToString();
            txtCustomerName.Text = dsApplication.Tables[2].Rows[0]["CustomerName"].ToString();
            txtPrefix.Text = dsApplication.Tables[2].Rows[0]["Title"].ToString();
            txtBeneficiary.Text = dsApplication.Tables[2].Rows[0]["Beneficiary"].ToString();
            txtInsuredPerson.Text = dsApplication.Tables[2].Rows[0]["Name"].ToString();
            txtContactNumber.Text = dsApplication.Tables[2].Rows[0]["ContactNo"].ToString();
            txtCurrentAddress.Text = dsApplication.Tables[2].Rows[0]["PresentAddress"].ToString();
            txtSubDistrict.Text = dsApplication.Tables[2].Rows[0]["SubDistrict"].ToString();
            txtStateProvince.Text = dsApplication.Tables[2].Rows[0]["District"].ToString();
            txtProvince.Text = dsApplication.Tables[2].Rows[0]["Province"].ToString();
            txtPostalCode.Text = dsApplication.Tables[2].Rows[0]["PostalCode"].ToString();
            txtPackage.Text = dsApplication.Tables[2].Rows[0]["Package"].ToString();

            if (dsApplication.Tables[2].Rows[0]["Gender"] != DBNull.Value)
            {
                ddlGender.Text = dsApplication.Tables[2].Rows[0]["Gender"].ToString();
            }

            DateTime DOB = dateTimeNow;
            if (dsApplication.Tables[2].Rows[0]["DOB"] != DBNull.Value && dsApplication.Tables[2].Rows[0]["DOB"].ToString() != string.Empty)
            {
                DOB = Convert.ToDateTime(dsApplication.Tables[2].Rows[0]["DOB"].ToString());
            }
            AssignDate(DOB.Day, ddlDOBDay);
            AssignMonth(DOB.Month, ddlDOBMonth);
            AssignYear(DOB.Year, ddlDOBYear);
            DateTime DriverDOB1 = dateTimeNow.AddYears(-20);
            DateTime DriverDOB2 = dateTimeNow.AddYears(-20);
            ddlOccupation.Text = dsApplication.Tables[2].Rows[0]["Occupation"].ToString();
            ddlNamedDriver.Text = dsApplication.Tables[2].Rows[0]["NoOfDriver"].ToString();
            ddlNamedDriver_SelectedIndexChanged(null, null);
            if (ddlNamedDriver.Text == "0")
            {
                txtDriverId1.Text = "0";
                txtDriverId2.Text = "0";
            }
            else if (ddlNamedDriver.Text == "1")
            {
                txtDriverId2.Text = "0";
            }
            if (dsApplication.Tables.Count > 3)
            {
                if (dsApplication.Tables[3].Rows.Count > 0 && dsApplication.Tables[3].Rows[0]["DOB"] != DBNull.Value && dsApplication.Tables[3].Rows[0]["DOB"].ToString() != string.Empty)
                {
                    DriverDOB1 = Convert.ToDateTime(dsApplication.Tables[3].Rows[0]["DOB"].ToString());
                }
                if (dsApplication.Tables[3].Rows.Count > 1 && dsApplication.Tables[3].Rows[1]["DOB"] != DBNull.Value && dsApplication.Tables[3].Rows[1]["DOB"].ToString() != string.Empty)
                {
                    DriverDOB2 = Convert.ToDateTime(dsApplication.Tables[3].Rows[1]["DOB"].ToString());
                }
                if (dsApplication.Tables[3].Rows.Count > 0)
                {
                    txtDriverFirst.Text = dsApplication.Tables[3].Rows[0]["FullName"].ToString();
                    txtDriver1IDNo.Text = dsApplication.Tables[3].Rows[0]["IDNo"].ToString();
                    txtDriver1LicenseNo.Text = dsApplication.Tables[3].Rows[0]["DrivingLicenseNumber"].ToString();
                    txtDriverId1.Text = dsApplication.Tables[3].Rows[0]["CarDriverId"].ToString();
                }
                if (dsApplication.Tables[3].Rows.Count > 1)
                {
                    txtDriverTwo.Text = dsApplication.Tables[3].Rows[1]["FullName"].ToString();
                    txtDriver2IDNo.Text = dsApplication.Tables[3].Rows[1]["IDNo"].ToString();
                    txtDriver2LicenseNo.Text = dsApplication.Tables[3].Rows[1]["DrivingLicenseNumber"].ToString();
                    txtDriverId2.Text = dsApplication.Tables[3].Rows[1]["CarDriverId"].ToString();
                }
            }
            AssignDate(DriverDOB1.Day, ddlDriver1DOBDay);
            AssignMonth(DriverDOB1.Month, ddlDriver1DOBMonth);
            AssignYear(DriverDOB1.Year, ddlDriver1DOBYear);
            AssignDate(DriverDOB2.Day, ddlDriver2DOBDay);
            AssignMonth(DriverDOB2.Month, ddlDriver2DOBMonth);
            AssignYear(DriverDOB2.Year, ddlDriver2DOBYear);

            DateTime _CreateDate = Convert.ToDateTime(dsApplication.Tables[2].Rows[0]["CreatedDate"].ToString());
            if (ddlApplicationDay.Items.Count > 0)
                ddlApplicationDay.Items.Clear();
            ddlApplicationDay.Items.Add(new ListItem(_CreateDate.Day.ToString("00"), _CreateDate.Day.ToString("00")));
            if (ddlApplicationMonth.Items.Count > 0)
                ddlApplicationMonth.Items.Clear();
            ddlApplicationMonth.Items.Add(new ListItem(_CreateDate.Month.ToString("00"), _CreateDate.Month.ToString("00")));
            if (ddlApplicationYear.Items.Count > 0)
                ddlApplicationYear.Items.Clear();
            ddlApplicationYear.Items.Add(new ListItem(_CreateDate.Year.ToString("0000"), _CreateDate.Year.ToString("0000")));

            if (ddlNamedDriver.Text == "0")
            {
                rfvDriverFirst.Enabled = false;
                revDriverFirst.Enabled = false;
                rfvDriver1IDNo.Enabled = false;
                rfvDriver1LicenseNo.Enabled = false;
                rfvDriverTwo.Enabled = false;
                revDriverTwo.Enabled = false;
                rfvDriver2IDNo.Enabled = false;
                rfvDriver2LicenseNo.Enabled = false;
            }
            if (ddlNamedDriver.Text == "1")
            {
                rfvDriverFirst.Enabled = true;
                revDriverFirst.Enabled = true;
                rfvDriver1IDNo.Enabled = true;
                rfvDriver1LicenseNo.Enabled = true;
                rfvDriverTwo.Enabled = false;
                revDriverTwo.Enabled = false;
                rfvDriver2IDNo.Enabled = false;
                rfvDriver2LicenseNo.Enabled = false;
            }
            if (ddlNamedDriver.Text == "2")
            {
                rfvDriverFirst.Enabled = true;
                revDriverFirst.Enabled = true;
                rfvDriver1IDNo.Enabled = true;
                rfvDriver1LicenseNo.Enabled = true;
                rfvDriverTwo.Enabled = true;
                revDriverTwo.Enabled = true;
                rfvDriver2IDNo.Enabled = true;
                rfvDriver2LicenseNo.Enabled = true;
            }

            pnlCarDetails.Visible = true;
            #endregion

        }
        else
        {
            lblSearchMessage.Text = Resources.General.CheckRefNo;
            divCar.Visible = false;
        }
        if (txtUserId.Text != "" && txtProviderId.Text != "")
        {
            GetCarMoreDetails();
        }
    }

    public void LoadLastYearApplicationDetails()
    {
        
        if (lblLastYearRefNo.Text != string.Empty)
        {
            DataSet _dsLastYearApplication = new DataSet();
            NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
            _dsLastYearApplication = _nonggpackagedb.GetLastYearCarDetails(Convert.ToInt64(txtCarId.Text.Trim()), lblLastYearRefNo.Text.ToUpper());
            if (_dsLastYearApplication != null && _dsLastYearApplication.Tables.Count > 0 && _dsLastYearApplication.Tables[0].Rows.Count > 0)
            {
                
                txtCarModelYear.Text = _dsLastYearApplication.Tables[0].Rows[0]["CarYear"].ToString();
                txtCarMakeModel.Text = _dsLastYearApplication.Tables[0].Rows[0]["CarModel"].ToString();
                if (_dsLastYearApplication.Tables[0].Rows[0]["InsuranceType"] != DBNull.Value)
                {
                    ddlInsuranceType.Text = _dsLastYearApplication.Tables[0].Rows[0]["InsuranceType"].ToString();
                }
                if (_dsLastYearApplication.Tables[0].Rows[0]["VehicleType"] != DBNull.Value)
                {
                    ddlVehicleType.Text = _dsLastYearApplication.Tables[0].Rows[0]["VehicleType"].ToString();
                }
                if (_dsLastYearApplication.Tables[0].Rows[0]["GarageType"] != DBNull.Value)
                {
                    ddlGarageType.Text = _dsLastYearApplication.Tables[0].Rows[0]["GarageType"].ToString();
                }
                txtCurrentInsurer.Text = _dsLastYearApplication.Tables[0].Rows[0]["CompanyName"].ToString();

                txtEngineNumber.Text = _dsLastYearApplication.Tables[0].Rows[0]["EngineNumber"].ToString();
                txtChassisNumber.Text = _dsLastYearApplication.Tables[0].Rows[0]["ChassisNumber"].ToString();
                txtPlateNumber.Text = _dsLastYearApplication.Tables[0].Rows[0]["CarPlate"].ToString();
                txtRegistrationProvince.Text = _dsLastYearApplication.Tables[0].Rows[0]["CarPlateProvince"].ToString();
                ddlNCB.Text = _dsLastYearApplication.Tables[0].Rows[0]["NCB"].ToString();
                
                txtUserId.Text = _dsLastYearApplication.Tables[0].Rows[0]["RefCEUserId"].ToString();

                lblUpApplicantName.Text = _dsLastYearApplication.Tables[0].Rows[0]["Name"].ToString();
                lblUpPlanName.Text = _dsLastYearApplication.Tables[0].Rows[0]["Package"].ToString();
                txtCancelStatus.Text = "0";

                ddlCustomerType.Text = _dsLastYearApplication.Tables[0].Rows[0]["CustomerType"].ToString();
                txtCustomerName.Text = _dsLastYearApplication.Tables[0].Rows[0]["CustomerName"].ToString();
                txtPrefix.Text = _dsLastYearApplication.Tables[0].Rows[0]["Title"].ToString();
                txtBeneficiary.Text = _dsLastYearApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
                txtInsuredPerson.Text = _dsLastYearApplication.Tables[0].Rows[0]["Name"].ToString();
                txtContactNumber.Text = _dsLastYearApplication.Tables[0].Rows[0]["ContactNo"].ToString();
                txtCurrentAddress.Text = _dsLastYearApplication.Tables[0].Rows[0]["PresentAddress"].ToString();
                txtSubDistrict.Text = _dsLastYearApplication.Tables[0].Rows[0]["SubDistrict"].ToString();
                txtStateProvince.Text = _dsLastYearApplication.Tables[0].Rows[0]["District"].ToString();
                txtProvince.Text = _dsLastYearApplication.Tables[0].Rows[0]["Province"].ToString();
                txtPostalCode.Text = _dsLastYearApplication.Tables[0].Rows[0]["PostalCode"].ToString();
                txtPackage.Text = _dsLastYearApplication.Tables[0].Rows[0]["Package"].ToString();

                if (_dsLastYearApplication.Tables[0].Rows[0]["Gender"] != DBNull.Value)
                {
                    ddlGender.Text = _dsLastYearApplication.Tables[0].Rows[0]["Gender"].ToString();
                }

                DateTime DOB = dateTimeNow;
                if (_dsLastYearApplication.Tables[0].Rows[0]["DOB"] != DBNull.Value && _dsLastYearApplication.Tables[0].Rows[0]["DOB"].ToString() != string.Empty)
                {
                    DOB = Convert.ToDateTime(_dsLastYearApplication.Tables[0].Rows[0]["DOB"].ToString());
                }
                AssignDate(DOB.Day, ddlDOBDay);
                AssignMonth(DOB.Month, ddlDOBMonth);
                AssignYear(DOB.Year, ddlDOBYear);
                DateTime DriverDOB1 = dateTimeNow.AddYears(-20);
                DateTime DriverDOB2 = dateTimeNow.AddYears(-20);
                ddlOccupation.Text = _dsLastYearApplication.Tables[0].Rows[0]["Occupation"].ToString();
                ddlNamedDriver.Text = _dsLastYearApplication.Tables[0].Rows[0]["NoOfDriver"].ToString();
                ddlNamedDriver_SelectedIndexChanged(null, null);
                txtDriverId1.Text = "0";
                txtDriverId2.Text = "0";
                if (_dsLastYearApplication.Tables.Count > 1 && ddlNamedDriver.Text != "0")
                {
                    if (_dsLastYearApplication.Tables[1].Rows.Count > 0 && _dsLastYearApplication.Tables[1].Rows[0]["DOB"] != DBNull.Value && _dsLastYearApplication.Tables[1].Rows[0]["DOB"].ToString() != string.Empty)
                    {
                        DriverDOB1 = Convert.ToDateTime(_dsLastYearApplication.Tables[1].Rows[0]["DOB"].ToString());
                    }
                    if (_dsLastYearApplication.Tables[1].Rows.Count > 1 && _dsLastYearApplication.Tables[1].Rows[1]["DOB"] != DBNull.Value && _dsLastYearApplication.Tables[1].Rows[1]["DOB"].ToString() != string.Empty)
                    {
                        DriverDOB2 = Convert.ToDateTime(_dsLastYearApplication.Tables[1].Rows[1]["DOB"].ToString());
                    }
                    if (_dsLastYearApplication.Tables[1].Rows.Count > 0)
                    {
                        txtDriverFirst.Text = _dsLastYearApplication.Tables[1].Rows[0]["FullName"].ToString();
                        txtDriver1IDNo.Text = _dsLastYearApplication.Tables[1].Rows[0]["IDNo"].ToString();
                        txtDriver1LicenseNo.Text = _dsLastYearApplication.Tables[1].Rows[0]["DrivingLicenseNumber"].ToString();
                    }
                    if (_dsLastYearApplication.Tables[1].Rows.Count > 1)
                    {
                        txtDriverTwo.Text = _dsLastYearApplication.Tables[1].Rows[1]["FullName"].ToString();
                        txtDriver2IDNo.Text = _dsLastYearApplication.Tables[1].Rows[1]["IDNo"].ToString();
                        txtDriver2LicenseNo.Text = _dsLastYearApplication.Tables[1].Rows[1]["DrivingLicenseNumber"].ToString();
                    }
                }
                AssignDate(DriverDOB1.Day, ddlDriver1DOBDay);
                AssignMonth(DriverDOB1.Month, ddlDriver1DOBMonth);
                AssignYear(DriverDOB1.Year, ddlDriver1DOBYear);
                AssignDate(DriverDOB2.Day, ddlDriver2DOBDay);
                AssignMonth(DriverDOB2.Month, ddlDriver2DOBMonth);
                AssignYear(DriverDOB2.Year, ddlDriver2DOBYear);

                DateTime _CreateDate = Convert.ToDateTime(_dsLastYearApplication.Tables[0].Rows[0]["CreatedDate"].ToString());
                if (ddlApplicationDay.Items.Count > 0)
                    ddlApplicationDay.Items.Clear();
                ddlApplicationDay.Items.Add(new ListItem(_CreateDate.Day.ToString("00"), _CreateDate.Day.ToString("00")));
                if (ddlApplicationMonth.Items.Count > 0)
                    ddlApplicationMonth.Items.Clear();
                ddlApplicationMonth.Items.Add(new ListItem(_CreateDate.Month.ToString("00"), _CreateDate.Month.ToString("00")));
                if (ddlApplicationYear.Items.Count > 0)
                    ddlApplicationYear.Items.Clear();
                ddlApplicationYear.Items.Add(new ListItem(_CreateDate.Year.ToString("0000"), _CreateDate.Year.ToString("0000")));

                if (ddlNamedDriver.Text == "0")
                {
                    rfvDriverFirst.Enabled = false;
                    revDriverFirst.Enabled = false;
                    rfvDriver1IDNo.Enabled = false;
                    rfvDriver1LicenseNo.Enabled = false;
                    rfvDriverTwo.Enabled = false;
                    revDriverTwo.Enabled = false;
                    rfvDriver2IDNo.Enabled = false;
                    rfvDriver2LicenseNo.Enabled = false;
                }
                if (ddlNamedDriver.Text == "1")
                {
                    rfvDriverFirst.Enabled = true;
                    revDriverFirst.Enabled = true;
                    rfvDriver1IDNo.Enabled = true;
                    rfvDriver1LicenseNo.Enabled = true;
                    rfvDriverTwo.Enabled = false;
                    revDriverTwo.Enabled = false;
                    rfvDriver2IDNo.Enabled = false;
                    rfvDriver2LicenseNo.Enabled = false;
                }
                if (ddlNamedDriver.Text == "2")
                {
                    rfvDriverFirst.Enabled = true;
                    revDriverFirst.Enabled = true;
                    rfvDriver1IDNo.Enabled = true;
                    rfvDriver1LicenseNo.Enabled = true;
                    rfvDriverTwo.Enabled = true;
                    revDriverTwo.Enabled = true;
                    rfvDriver2IDNo.Enabled = true;
                    rfvDriver2LicenseNo.Enabled = true;
                }
            }
        }
    }

    public void GetCarMoreDetails()
    {
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        string _spName = "sprocCXCRMNonGGCarMoreDetailSelectSingleItem";
        SortedList _spara = new SortedList();
        _spara.Add("@CECarId", Convert.ToInt64(txtCarId.Text.Trim()));
        _spara.Add("@RefCEUserId", Convert.ToInt64(txtUserId.Text));
        _spara.Add("@ProviderCompanyId", Convert.ToInt64(txtProviderId.Text));
        DataSet _dsCarMoreDetails = new DataSet();
        _dsCarMoreDetails = _db.GetDataSet(_spName, _spara);
        if (_dsCarMoreDetails != null && _dsCarMoreDetails.Tables.Count > 0 && _dsCarMoreDetails.Tables[1].Rows.Count > 0)
        {
            lblPRefNo.Text = _dsCarMoreDetails.Tables[1].Rows[0]["QuoteRefNo"].ToString();
            lblUpRefNo.Text = _dsCarMoreDetails.Tables[1].Rows[0]["QuoteRefNo"].ToString();
            lblUpApplicantName.Text = _dsCarMoreDetails.Tables[1].Rows[0]["Name"].ToString();
            lblUpInsurer.Text = _dsCarMoreDetails.Tables[1].Rows[0]["CompanyName"].ToString();
            lblUpPlanName.Text = _dsCarMoreDetails.Tables[1].Rows[0]["Package"].ToString();
            txtCancelStatus.Text = "0";
            if (_dsCarMoreDetails.Tables[0].Rows[0]["CancelStatus"] != DBNull.Value && _dsCarMoreDetails.Tables[0].Rows[0]["CancelStatus"].ToString() != "")
            {
                txtCancelStatus.Text = _dsCarMoreDetails.Tables[0].Rows[0]["CancelStatus"].ToString();
            }
            if (txtCancelStatus.Text == "1")
            {
                ddlOption.Items.Clear();
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Retrieve, "RTRV"));
                ddlOption.SelectedIndex = 0;
            }
            else
            {
                LoadOption();
            }

            if (_dsCarMoreDetails.Tables.Count > 1 && _dsCarMoreDetails.Tables[1].Rows.Count > 0)
            {
                txtBalanceAmount.Text = _dsCarMoreDetails.Tables[1].Rows[0]["TotalCollectedPremium"].ToString();
                lblUpPremium.Text = _dsCarMoreDetails.Tables[1].Rows[0]["TotalCollectedPremium"].ToString();
                lblUpPaymentType.Text = _dsCarMoreDetails.Tables[1].Rows[0]["PaymentType"].ToString();
                lblUpPaymentStatus.Text = _dsCarMoreDetails.Tables[1].Rows[0]["PaymentStatus"].ToString();
            }
            if (ddlOption.Items.Count > 0)
            {
                ddlOption_SelectedIndexChanged(null, null);
            }
        }
        else
        {
            
            DataSet _dsCarDetails = new DataSet();
            _dsCarDetails = GetBrokerPremium();
            if (_dsCarDetails != null && _dsCarDetails.Tables.Count > 0 && _dsCarDetails.Tables[0].Rows.Count > 0)
            {
                pnlDetails.Visible = true;
                lblPRefNo.Text = _dsCarDetails.Tables[0].Rows[0]["Info1"].ToString();
                lblUpRefNo.Text = _dsCarDetails.Tables[0].Rows[0]["Info1"].ToString();
                if (_dsCarDetails.Tables[0].Rows[0]["Info4"] != DBNull.Value && _dsCarDetails.Tables[0].Rows[0]["Info4"].ToString() == "1")
                {
                    lblCompanyStaff.Text = "1";
                    if (Session[General.UserRole].ToString() == "100")
                    {
                        lblOptionError.Text = Resources.Proposal.AccessDenied;
                        btnSubmit.Enabled = false;
                    }
                }
                else
                {
                    lblCompanyStaff.Text = "0";
                }
                
                lblUpInsurer.Text = CE.Global.General.GetProviderName(Convert.ToInt64(txtProviderId.Text), lblLangOption.Text);
                lblUpPlanName.Text = _dsCarDetails.Tables[0].Rows[0]["Package"].ToString();
                lblUpPremium.Text = _dsCarDetails.Tables[0].Rows[0]["PremiumAmount"].ToString();
                txtBalanceAmount.Text = _dsCarDetails.Tables[0].Rows[0]["PremiumAmount"].ToString();
                lblUpPaymentStatus.Text = "PENDING";
                if (_dsCarDetails != null && _dsCarDetails.Tables.Count > 1 && _dsCarDetails.Tables[1].Rows.Count > 0)
                {
                    lblUpPaymentStatus.Text = "PENDING";
                }
            }
        }

        if (_dsCarMoreDetails != null && _dsCarMoreDetails.Tables.Count > 0 && _dsCarMoreDetails.Tables[0].Rows.Count > 0)
        {
            if (_dsCarMoreDetails.Tables[0].Rows[0]["Mailing"] != DBNull.Value && _dsCarMoreDetails.Tables[0].Rows[0]["Mailing"].ToString() != string.Empty)
            {
                if (_dsCarMoreDetails.Tables[0].Rows[0]["Mailing"].ToString() == "1")
                {
                    ddlOption.Items.Clear();
                    ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                    ddlOption.Items.Add(new ListItem(Resources.CarInsurance.UploadFile, "UPLD"));
                    ddlOption.SelectedIndex = 0;
                }
            }
        }
    }

    public DataSet GetBrokerPremium()
    {
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMBrokerPremiumSelectSingleItem";
        _sPara.Add("@CXBrokerProviderId", Convert.ToInt64(txtProviderId.Text));
        _sPara.Add("@CECarId", Convert.ToInt64(txtCarId.Text.Trim()));
        _sPara.Add("@SelectedStatus", true);
        DataSet _ds = new DataSet();
        return _ds = _db.GetDataSet(_spName, _sPara);
        
    }

    public DataSet GetPaymentAmounts()
    {
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMPaymentsAmountsSelectItembyQuoteRefNo";
        _sPara.Add("@QuoteRefNo", lblUpRefNo.Text);
        DataSet _ds = new DataSet();
        return _ds = _db.GetDataSet(_spName, _sPara);
        
    }

    public bool CheckSelectedItem(string QouteRefNo)
    {
        bool _Result = false;
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMNonGGPremiumSelectItemByQuoteRefNo";
        _sPara.Add("@QouteRefNo", QouteRefNo);
        DataSet _ds = new DataSet();
        _ds = _db.GetDataSet(_spName, _sPara);
        if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
        {
            _Result = true;
        }
        return _Result;
    }

    public bool CheckApplicationProcessStatus(string QouteRefNo, string Process)
    {
        bool _Result = true;
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        SortedList _sPara = new SortedList();
        string _spName = "sprocCXCRMNonGGApplicationSelectItemByQuoteRefNo";
        _sPara.Add("@QuoteRefNo", QouteRefNo);
        DataSet _ds = new DataSet();
        _ds = _db.GetDataSet(_spName, _sPara);
        if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
        {
            string _status = "";
            if (Process.ToUpper() == "MAILING")
            {
                if (_ds.Tables[0].Rows[0]["Mailing"].ToString() != null && _ds.Tables[0].Rows[0]["Mailing"].ToString() != string.Empty)
                {
                    _status = _ds.Tables[0].Rows[0]["Mailing"].ToString();
                    if (_status != string.Empty && _status == "1")
                    {
                        _Result = false;
                    }
                }
            }
        }
        return _Result;
    }

    private bool GetBoolean(Int16 val)
    {
        bool _result = false;
        if (val == 1)
        {
            _result = true;
        }
        return _result;
    }

    private void AssignDate(Int32 _date, DropDownList ddl)
    {
        string val = _date.ToString();
        if (_date < 10)
        {
            val = "0" + _date.ToString();
        }
       
        ddl.Text = val;
    }

    private void AssignMonth(Int32 _month, DropDownList ddl)
    {
        string val = "00";
        string monthname = Resources.General.Select;
        if (_month < 10)
        {
            val = "0" + _month.ToString();
        }
        else
        {
            val = _month.ToString();
        }
       
        ddl.Text = val;
    }

    private void AssignYear(Int32 _year, DropDownList ddl)
    {
        if (_year > (dateTimeNow.Year + 400))
        {
            _year = _year - 543;
        }
        string val = _year.ToString();
       
        ddl.Text = val;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Page.Validate("nongg");

        if (lblCompanyStaff.Text == "1" && Session[General.UserRole].ToString() == "100")
        {
            lblOptionError.Text = Resources.Proposal.AccessDenied;
            return;
        }

        if (Page.IsValid)
        {
            lblLoadMessage.Text = string.Empty;
            Int64 _result = -1;
            Int64 _AgentId = 0;
            Int64 _AdminId = 0;
            if (!Int64.TryParse(lblAgentId.Text, out _AgentId))
            {
                _AgentId = 0;
            }
            if (!Int64.TryParse(lblAdminId.Text, out _AdminId))
            {
                _AdminId = 0;
            }
            txtLastQuoteRefNo.Text = txtSearch.Text.Trim();
            NonGGPackage _nonggpackage = new NonGGPackage();
            NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
            _nonggpackage.CECarId = Convert.ToInt64(txtCarId.Text);
            _nonggpackage.ProviderCompanyId = Convert.ToInt64(txtProviderId.Text);
            _nonggpackage.Title = Server.HtmlEncode(txtPrefix.Text);
            _nonggpackage.CustomerType = ddlCustomerType.Text;
            _nonggpackage.CustomerName = Server.HtmlEncode(txtCustomerName.Text);
            _nonggpackage.Name = Server.HtmlEncode(txtInsuredPerson.Text);
            DateTime _dtDOB = new DateTime(Convert.ToInt32(ddlDOBYear.Text), Convert.ToInt32(ddlDOBMonth.Text), Convert.ToInt32(ddlDOBDay.Text));
            _nonggpackage.DOB = _dtDOB;
            _nonggpackage.Gender = ddlGender.Text;
            _nonggpackage.Occupation = Convert.ToInt32(ddlOccupation.Text);
            _nonggpackage.ContactNo = Server.HtmlEncode(txtContactNumber.Text);
            _nonggpackage.PresentAddress = Server.HtmlEncode(txtCurrentAddress.Text);
            _nonggpackage.SubDistrict = Server.HtmlEncode(txtSubDistrict.Text);
            _nonggpackage.District = Server.HtmlEncode(txtStateProvince.Text);
            _nonggpackage.Province = Server.HtmlEncode(txtProvince.Text);
            _nonggpackage.PostalCode = txtPostalCode.Text;
            _nonggpackage.Package = Server.HtmlEncode(txtPackage.Text);
            _nonggpackage.NoOfDriver = Convert.ToInt16(ddlNamedDriver.Text);
            _nonggpackage.InsuranceType = Convert.ToInt32(ddlInsuranceType.Text);
            _nonggpackage.GarageType = Convert.ToInt32(ddlGarageType.Text);
            _nonggpackage.CarYear = Convert.ToInt32(txtCarModelYear.Text);
            _nonggpackage.CarModel = Server.HtmlEncode(txtCarMakeModel.Text);
          
            _nonggpackage.Beneficiary = Server.HtmlEncode(txtBeneficiary.Text);
            _nonggpackage.VehicleType = Convert.ToInt32(ddlVehicleType.Text);
           
            Int32 _outSumInsurred = 0;
            if (!Int32.TryParse(txtSumInsured.Text, out _outSumInsurred))
            {
                _outSumInsurred = 0;
            }
            _nonggpackage.SumInsured = _outSumInsurred;
            _nonggpackage.NCB = Convert.ToInt32(ddlNCB.Text);
            _nonggpackage.CurrentInsurer = Server.HtmlEncode(txtCurrentInsurer.Text);
            _nonggpackage.CarPlate = Server.HtmlEncode(txtPlateNumber.Text);
            _nonggpackage.CarPlateProvince = Server.HtmlEncode(txtRegistrationProvince.Text);
            _nonggpackage.EngineNumber = Server.HtmlEncode(txtEngineNumber.Text);
            _nonggpackage.ChassisNumber = Server.HtmlEncode(txtChassisNumber.Text);
         
            DateTime _dtCommDate = new DateTime(Convert.ToInt32(ddlCommenceYear.Text), Convert.ToInt32(ddlCommenceMonth.Text), Convert.ToInt32(ddlCommenceDay.Text));
            _nonggpackage.CoverageStart = _dtCommDate;
            DateTime _dtPolicyDate = new DateTime(Convert.ToInt32(ddlPolicyYear.Text), Convert.ToInt32(ddlPolicyMonth.Text), Convert.ToInt32(ddlPolicyDay.Text));
            _nonggpackage.CTPLStart = _dtPolicyDate;

            _nonggpackage.Premium = Convert.ToSingle(txtInsurancePremium.Text);
            _nonggpackage.IsCTPL = GetBoolean(Convert.ToInt16(ddlCTPL.Text));
            _nonggpackage.CTPL = Convert.ToSingle(txtCTPL.Text);

            _nonggpackage.TotalCollectedPremium = Convert.ToSingle(txtCollectedAmount.Text);
            _nonggpackage.TotalPremium = Convert.ToSingle(txtTotalPremium.Text);
            _nonggpackage.TermPremium = Convert.ToSingle(txtTotalPremium.Text);
           
            _nonggpackage.QuoteRefNo = txtNewQuoteRefNo.Text;
            _nonggpackage.Status = true;
            _nonggpackage.RefCEUserId = Convert.ToInt64(txtUserId.Text);
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "100")
            {
                _nonggpackage.AgentId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                _nonggpackage.AdminId = _AdminId;
            }
            else
            {
                if (_AgentId == 0)
                {
                    _nonggpackage.AgentId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _nonggpackage.AgentId = _AgentId;
                }

                _nonggpackage.AdminId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            }
            _nonggpackage.Info1 = ddlApplicationType.Text;
            if (ddlApplicationType.Text == "REN" || ddlApplicationType.Text == "CHB")
            {
                _nonggpackage.Info2 = txtLastYearPolicyNo.Text.Trim();
            }
            _result = _nonggpackagedb.Insert(_nonggpackage);
            Int32 driverresult = 0;
            if (_result > 0)
            {
                if (Convert.ToInt16(ddlNamedDriver.Text) > 0)
                {
                    if (SaveDriverDetails())
                    {
                        driverresult = 1;
                        pnlCarDetails.Visible = false;
                        lblOptionMessage.Text = Resources.CarInsurance.SuccessfullySaved;
                        pnlOptionMessage.Visible = true;
                        pnlDetails.Visible = true;
                        divCar.Visible = true;
                    }
                    else
                    {
                        driverresult = 0;
                    }
                }
                else
                {
                    driverresult = 1;
                }
                if (driverresult > 0)
                {
                    string _fileName = lblUpRefNo.Text.Trim() + "_" + dateTimeNow.Day.ToString("00") + "-" + dateTimeNow.Month.ToString("00") + "-" + dateTimeNow.Year;
                    string _filePath = GetExcelFilePath(Convert.ToInt64(txtProviderId.Text.Trim()), lblUpRefNo.Text.Trim());
                    string ExcelFile = GenerateNonGGExcel(_nonggpackage.CECarId, _nonggpackage.ProviderCompanyId, _filePath, _fileName);
                    if (ExcelFile != null)
                    {
                        Int64 _excelResult = -1;
                        _excelResult = _nonggpackagedb.UpdateExcelName(_nonggpackage.CECarId, ExcelFile);
                        if (_excelResult > 0)
                        {
                            string mailBody = "";
                            string _emailTitle = "";
                            string _toemail = "";
                            string _ccemail = "";
                            string _bccemail = "";
                            _emailTitle = "[" + lblUpRefNo.Text + "] ส่งงานประกันรถ คุณ [" + _nonggpackage.Name + "] [" + _nonggpackage.CarPlate + "]";
                            if (ddlApplicationType.Text == "NEW")
                            {
                                mailBody += Resources.Proposal.ApplicationType + " : " + Resources.Proposal.AppTypeNew + "<br/><br/>";
                            }
                            else if (ddlApplicationType.Text == "REN")
                            {
                                mailBody += Resources.Proposal.ApplicationType + " : " + Resources.Proposal.AppTypeRenewalSameInsurer + "<br/><br/>";
                            }
                            else if (ddlApplicationType.Text == "RNO")
                            {
                                mailBody += Resources.Proposal.ApplicationType + " : " + Resources.Proposal.AppTypeRenewalOtherInsurer + "<br/><br/>";
                            }
                            else if (ddlApplicationType.Text == "CHB")
                            {
                                mailBody += Resources.Proposal.ApplicationType + " : " + Resources.Proposal.AppTypeChangeBroker + "<br/><br/>";
                            }
                            mailBody += Resources.General.CustomerName + " : " + _nonggpackage.Name + "<br/><br/>";
                            mailBody += Resources.General.InsuranceCompany + " : " + txtInsuranceCompany.Text.Trim() + "<br/><br/>";
                            mailBody += Resources.General.InsuranceType + " : " + ddlInsuranceType.SelectedItem.Text + "<br/><br/>";
                            mailBody += Resources.NonGG.GarageType + " : " + ddlGarageType.SelectedItem.Text + "<br/><br/>";
                            mailBody += Resources.General.TotalCollectedAmount + " : " + txtCollectedAmount.Text.Trim() + "<br/><br/>";
                            string URL = ConfigurationManager.AppSettings["TH.BKKPaymentPage"].ToString(); //http://www.gluaygluay.com/payment/
                            mailBody += Resources.General.PaymentLink + " : " + URL + "?ref=" + lblUpRefNo.Text.Trim() + "<br/><br/>";
                            mailBody += Resources.General.Broker + " : " + Session[CE.Global.General.UserName].ToString() + "<br/><br/>";
                            _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ADMIN");
                            _toemail += CE.Configuration.MyConfigurationManager.GetAppSettingValue("CASH");
                            _ccemail = "";//Session[CE.Global.General.UserEmail].ToString();
                            _bccemail = "";
                            if (Session[General.UserRole].ToString() == "100")
                            {
                                _ccemail += Session[General.SMTPReplyTo].ToString();
                            }

                            bool _mailSendingStatus = false;

                           

                            _mailSendingStatus = MyMailManager.SendGGMail(ConfigurationManager.AppSettings["GGFormsSMTPAccount"].ToString(), ConfigurationManager.AppSettings["GGFormsSMTPAuthCode"].ToString(), _toemail, _ccemail, _bccemail, _emailTitle, mailBody, Session[General.SMTPReplyTo].ToString());

                            pnlCarDetails.Visible = false;
                            lblOptionMessage.Text = Resources.CarInsurance.SuccessfullySaved;
                            pnlOptionMessage.Visible = true;
                            divCar.Visible = true;

                            if (!_mailSendingStatus)
                            {
                                lblOptionMessage.Text += ". Email notification was FAILED.";
                            }
                            ddlOption.SelectedIndex = 0;
                            ddlOption_SelectedIndexChanged(null, null);

                        }
                    }
                }
            }
        }
        else
        {
            lblOptionError.Text = Resources.CarInsurance.SuccessfullySaved;
            pnlOptionMessage.Visible = true;
        }
    }

    protected void ddlApplicationType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlApplicationType.Text == "NEW")
        {
            lblLastYearPolicyNoTitle.Text = string.Empty;
            rfvLastYearPolicyNo.Enabled = false;
            txtLastYearPolicyNo.Visible = false;
            txtLastYearPolicyNo.Text = "";
            txtLastYearPolicyNo.Enabled = true;
        }
        else if (ddlApplicationType.Text == "REN")
        {
            lblLastYearPolicyNoTitle.Text = Resources.Proposal.LastYearPolicyNo;
            rfvLastYearPolicyNo.Enabled = true;
            txtLastYearPolicyNo.Visible = true;
            txtLastYearPolicyNo.Text = lblLastYearPolicyNo.Text;
            txtLastYearPolicyNo.Enabled = false;
        }
        else if (ddlApplicationType.Text == "RNO")
        {
            lblLastYearPolicyNoTitle.Text = string.Empty;
            rfvLastYearPolicyNo.Enabled = false;
            txtLastYearPolicyNo.Visible = false;
            txtLastYearPolicyNo.Text = "";
            txtLastYearPolicyNo.Enabled = true;
        }
        else if (ddlApplicationType.Text == "CHB")
        {
            lblLastYearPolicyNoTitle.Text = Resources.Proposal.LastYearPolicyNo;
            rfvLastYearPolicyNo.Enabled = true;
            txtLastYearPolicyNo.Visible = true;
            txtLastYearPolicyNo.Text = "";
            txtLastYearPolicyNo.Enabled = true;
            if (lblNonGGStatus.Text == "1")
            {
                txtLastYearPolicyNo.Text = lblLastYearPolicyNo.Text;
            }
        }
    }

    protected void ddlCTPL_SelectedIndexChanged(object sender, EventArgs e)
    {
        float TotalPremium = Convert.ToSingle(txtInsurancePremium.Text);
        if (ddlCTPL.Text == "1")
        {
            TotalPremium = Convert.ToSingle(txtInsurancePremium.Text) + Convert.ToSingle(txtCTPL.Text);
        }
        txtTotalPremium.Text = TotalPremium.ToString("#0.00");
    }

    protected void ddlNamedDriver_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt16(ddlNamedDriver.Text) == 0)
        {
            rfvDriverFirst.Enabled = false;
            revDriverFirst.Enabled = false;
            rfvDriver1IDNo.Enabled = false;
            rfvDriver1LicenseNo.Enabled = false;
            rfvDriverTwo.Enabled = false;
            revDriverTwo.Enabled = false;
            rfvDriver2IDNo.Enabled = false;
            rfvDriver2LicenseNo.Enabled = false;

            ddlDriver1DOBDay.Enabled = false;
            ddlDriver1DOBMonth.Enabled = false;
            ddlDriver1DOBYear.Enabled = false;
            txtDriverFirst.Enabled = false;
            txtDriver1IDNo.Enabled = false;
            txtDriver1LicenseNo.Enabled = false;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;
            txtDriverTwo.Enabled = false;
            txtDriver2IDNo.Enabled = false;
            txtDriver2LicenseNo.Enabled = false;
        }
        else if (Convert.ToInt16(ddlNamedDriver.Text) == 1)
        {
            rfvDriverFirst.Enabled = true;
            revDriverFirst.Enabled = true;
            rfvDriver1IDNo.Enabled = true;
            rfvDriver1LicenseNo.Enabled = true;
            rfvDriverTwo.Enabled = false;
            revDriverTwo.Enabled = false;
            rfvDriver2IDNo.Enabled = false;
            rfvDriver2LicenseNo.Enabled = false;

            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            txtDriverFirst.Enabled = true;
            txtDriver1IDNo.Enabled = true;
            txtDriver1LicenseNo.Enabled = true;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;
            txtDriverTwo.Enabled = false;
            txtDriver2IDNo.Enabled = false;
            txtDriver2LicenseNo.Enabled = false;
        }
        else if (Convert.ToInt16(ddlNamedDriver.Text) == 2)
        {
            rfvDriverFirst.Enabled = true;
            revDriverFirst.Enabled = true;
            rfvDriver1IDNo.Enabled = true;
            rfvDriver1LicenseNo.Enabled = true;
            rfvDriverTwo.Enabled = true;
            revDriverTwo.Enabled = true;
            rfvDriver2IDNo.Enabled = true;
            rfvDriver2LicenseNo.Enabled = true;

            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            txtDriverFirst.Enabled = true;
            txtDriver1IDNo.Enabled = true;
            txtDriver1LicenseNo.Enabled = true;
            ddlDriver2DOBDay.Enabled = true;
            ddlDriver2DOBMonth.Enabled = true;
            ddlDriver2DOBYear.Enabled = true;
            txtDriverTwo.Enabled = true;
            txtDriver2IDNo.Enabled = true;
            txtDriver2LicenseNo.Enabled = true;
        }
        lblLoadMessage.Text = string.Empty;
    }

    protected void ddlOption_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblPayError.Text = "";
        lblOnlinePayError.Text = "";
        Span1.InnerHtml = "";
        txtRemark.Text = "";
        ClearPayFields();
        lblOptionError.Text = string.Empty;
        if (ddlOption.Text == "EDIT")
        {
            lblOptionError.Text = string.Empty;
            lblOptionMessage.Text = string.Empty;
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
          
            pnlDetails.Visible = true;
            pnlCarDetails.Visible = true;
            pnlPayment.Visible = false;
            pnlApplicationCancel.Visible = false;
            pnlApplicationRetrieve.Visible = false;
            pnlUploadFileList.Visible = false;
          


           
            DataSet _dsPayment = GetPaymentAmounts();
            if (_dsPayment != null && _dsPayment.Tables.Count > 0 && _dsPayment.Tables[0].Rows.Count > 0)
            {
                lblBalanceAmount.Text = _dsPayment.Tables[0].Rows[0]["BalanceAmount"].ToString();
            }
            else
            {
                lblBalanceAmount.Text = txtTotalPremium.Text;
            }
            if (pnlCarDetails.Visible == true)
            {
                ddlOption.Text = "EDIT";
            }
        }
        else if (ddlOption.Text == "PAYM")
        {
            //Sakthi 14 Jun 2012 -Start
            chkApprove.Enabled = false;
            chkRefund.Enabled = false;
            //Sakthi 14 Jun 2012 -End
            txtOnlineApproveStatus.Text = "0";
            lblOptionError.Text = string.Empty;
            lblOptionMessage.Text = string.Empty;
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
            pnlDetails.Visible = true;
            pnlCarDetails.Visible = false;
            pnlPayment.Visible = true;
            pnlApplicationCancel.Visible = false;
            pnlApplicationRetrieve.Visible = false;
            pnlUploadFileList.Visible = false;

            txtBalanceAmount.Text = "0";
            txtTotalCollectedAmount.Text = "0";
            txtTotalRefundAmount.Text = "0";
            DataSet _dsPayment = new DataSet();
            _dsPayment = GetBrokerPremium();
            if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
            {
                grvPayment.DataSource = _dsPayment.Tables[1];
                grvPayment.DataBind();
                txtPaymentId.Text = "0";
                EnableDisable();
                if (grvPayment.Rows.Count > 0)
                {
                    //Sakthi 14 Jun 2012 -Start
                    chkRefund.Enabled = true;
                    chkApprove.Enabled = false;
                    //Sakthi 14 Jun 2012 -End
                    DataSet _dsPaymentAmount = new DataSet();
                    _dsPaymentAmount = GetPaymentAmounts();
                    if (_dsPaymentAmount != null && _dsPaymentAmount.Tables.Count > 0 && _dsPaymentAmount.Tables[0].Rows.Count > 0)
                    {
                        txtBalanceAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["BalanceAmount"].ToString();
                        txtTotalCollectedAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString();
                        txtTotalRefundAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["RefundAmount"].ToString();
                    }
                    divPayList.Visible = true;
                }
                else
                {
                    divPayList.Visible = false;
                }
            }
            else
            {
                txtBalanceAmount.Text = lblUpPremium.Text;
            }
            if (txtPaymentId.Text == "0")
            {
                chkRefund.Enabled = true;
            }
            else
            {
                chkRefund.Enabled = false;
            }

            float _onlineAmount = 0.0f;
            DataSet _dsApplication = new DataSet();
            NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
            _dsApplication = _nonggpackagedb.GetCarDetails(Convert.ToInt64(txtCarId.Text.Trim()), Convert.ToInt64(txtUserId.Text.Trim()));




            if (_dsApplication.Tables[2].Rows.Count > 0 && _dsApplication.Tables[2].Rows[0]["ONLPaymentStatus"] != DBNull.Value && _dsApplication.Tables[2].Rows[0]["ONLPaymentStatus"].ToString() != string.Empty
                && _dsApplication.Tables[2].Rows[0]["ONLPaymentStatus"].ToString().ToUpper() == "1")
            {

                if (_dsApplication.Tables[2].Rows[0]["DeclineStatus"] != DBNull.Value && _dsApplication.Tables[2].Rows[0]["DeclineStatus"].ToString() != string.Empty
                && _dsApplication.Tables[2].Rows[0]["DeclineStatus"].ToString() == "1")
                {
                    pnlPaymentInput.Visible = true;
                    lblOnlinePayError.Text = Resources.General.OnlinePaymentDecline;
                 
                    btnOnlinePaySubmit.Visible = false;
                    btnOnlinePayDecline.Visible = false;
                }
                else
                {
                    PaymentsDB _paymentsdb = new PaymentsDB();
                    DataSet _dsOLPayments = new DataSet();
                    _dsOLPayments = _paymentsdb.GetPayments(Convert.ToInt64(txtCarId.Text), 1);
                    if (_dsOLPayments != null && _dsOLPayments.Tables[0].Rows.Count > 0)
                    {
                        pnlPaymentInput.Visible = true;
                        txtOnlineApproveStatus.Text = "1";
                        lblOnlinePayError.Text = Resources.General.OnlinePaymentApprove;
                     
                        btnOnlinePaySubmit.Visible = false;
                        btnOnlinePayDecline.Visible = false;
                    }
                    else
                    {
                        grvPayment.Enabled = false;
                        pnlPaymentInput.Visible = false;
                      
                        btnOnlinePaySubmit.Visible = true;
                        btnOnlinePayDecline.Visible = true;
                    }
                }



                if (_dsApplication.Tables[2].Rows[0]["ONLPaymentCode"] != DBNull.Value && _dsApplication.Tables[2].Rows[0]["ONLPaymentCode"].ToString() != string.Empty
                    && _dsApplication.Tables[2].Rows[0]["ONLPaymentCode"].ToString() == "1")
                {
                    pnlOnlinePayment.Visible = true;
                    txtOnlinePaymentType.Text = "CreditCard";
                    if (_dsApplication.Tables[2].Rows[0]["FinalAnnualPremium"] != DBNull.Value && _dsApplication.Tables[2].Rows[0]["FinalAnnualPremium"].ToString() != string.Empty)
                    {
                        _onlineAmount = Convert.ToSingle(_dsApplication.Tables[2].Rows[0]["FinalAnnualPremium"].ToString());
                        txtOnlineAmount.Text = _onlineAmount.ToString("#000.00");
                        txtAppStatus.Text = "OFFLINE";
                    }
                    else
                    {
                        txtOnlineAmount.Text = "0";
                    }
                    if (_dsApplication.Tables[2].Rows[0]["OrderRefNo"] != DBNull.Value && _dsApplication.Tables[2].Rows[0]["OrderRefNo"].ToString() != string.Empty)
                    {
                        txtOnlinePaymentRefNo.Text = _dsApplication.Tables[2].Rows[0]["OrderRefNo"].ToString();
                    }
                    else
                    {
                        txtOnlinePaymentRefNo.Text = "";
                    }
                }
                else
                {
                    pnlPaymentInput.Visible = true;
                    pnlOnlinePayment.Visible = false;
                    txtOnlinePaymentType.Text = "ONLINE";
                    txtOnlineAmount.Text = "0";
                    txtOnlinePaymentRefNo.Text = "";
                }
            }
            else if (_dsApplication != null && _dsApplication.Tables.Count > 4 && _dsApplication.Tables[4].Rows.Count > 0)
            {
                if (_dsApplication.Tables[4].Rows[0]["DeclineStatus"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["DeclineStatus"].ToString() != string.Empty
                    && _dsApplication.Tables[4].Rows[0]["DeclineStatus"].ToString() == "1")
                {
                    pnlPaymentInput.Visible = true;
                    lblOnlinePayError.Text = Resources.General.OnlinePaymentDecline;
               
                    btnOnlinePaySubmit.Visible = false;
                    btnOnlinePayDecline.Visible = false;
                }
                else
                {
                    PaymentsDB _paymentsdb = new PaymentsDB();
                    DataSet _dsOLPayments = new DataSet();
                    _dsOLPayments = _paymentsdb.GetPayments(Convert.ToInt64(txtCarId.Text), 1);
                    if (_dsOLPayments != null && _dsOLPayments.Tables[0].Rows.Count > 0)
                    {
                        pnlPaymentInput.Visible = true;
                        txtOnlineApproveStatus.Text = "1";
                        lblOnlinePayError.Text = Resources.General.OnlinePaymentApprove;
                    
                        btnOnlinePaySubmit.Visible = false;
                        btnOnlinePayDecline.Visible = false;
                    }
                    else
                    {
                        grvPayment.Enabled = false;
                        pnlPaymentInput.Visible = false;
                     
                        btnOnlinePaySubmit.Visible = true;
                        btnOnlinePayDecline.Visible = true;
                    }
                }



                if (_dsApplication.Tables[4].Rows[0]["PaymentType"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["PaymentType"].ToString() != string.Empty
                    && _dsApplication.Tables[4].Rows[0]["PaymentType"].ToString().ToUpper() == "CREDITCARD")
                {
                    if (_dsApplication.Tables[4].Rows[0]["PaymentCode"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["PaymentCode"].ToString() != string.Empty
                        && _dsApplication.Tables[4].Rows[0]["PaymentCode"].ToString() == "1")
                    {
                        pnlOnlinePayment.Visible = true;
                        txtOnlinePaymentType.Text = "CreditCard";
                        if (_dsApplication.Tables[4].Rows[0]["AnnualPremium"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["AnnualPremium"].ToString() != string.Empty)
                        {
                            _onlineAmount = Convert.ToSingle(_dsApplication.Tables[4].Rows[0]["AnnualPremium"].ToString());
                            txtOnlineAmount.Text = _onlineAmount.ToString("#000.00");
                            txtAppStatus.Text = "ONLINE";
                        }
                        else
                        {
                            txtOnlineAmount.Text = "0";
                        }
                        if (_dsApplication.Tables[4].Rows[0]["OrderRefNo"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["OrderRefNo"].ToString() != string.Empty)
                        {
                            txtOnlinePaymentRefNo.Text = _dsApplication.Tables[4].Rows[0]["OrderRefNo"].ToString();
                        }
                        else
                        {
                            txtOnlinePaymentRefNo.Text = "";
                        }
                    }
                    else
                    {
                        grvPayment.Enabled = true;
                        pnlPaymentInput.Visible = true;
                        pnlOnlinePayment.Visible = false;
                        txtOnlinePaymentType.Text = "ONLINE";
                        txtOnlineAmount.Text = "0";
                        txtOnlinePaymentRefNo.Text = "";
                    }
                }
                else
                {
                    pnlOnlinePayment.Visible = true;
                    txtOnlinePaymentType.Text = "BankTransfer";
                    if (_dsApplication.Tables[4].Rows[0]["AnnualPremium"] != DBNull.Value && _dsApplication.Tables[4].Rows[0]["AnnualPremium"].ToString() != string.Empty)
                    {
                        _onlineAmount = Convert.ToSingle(_dsApplication.Tables[4].Rows[0]["AnnualPremium"].ToString());
                        txtOnlineAmount.Text = _onlineAmount.ToString("#000.00");
                        txtAppStatus.Text = "ONLINE";
                    }
                    else
                    {
                        txtOnlineAmount.Text = "0";
                    }
                    txtOnlinePaymentRefNo.Text = "";
                }
            }
            else
            {
                grvPayment.Enabled = true;
                pnlPaymentInput.Visible = true;
                pnlOnlinePayment.Visible = false;
                txtOnlinePaymentType.Text = "ONLINE";
                txtOnlineAmount.Text = "0";
                txtOnlinePaymentRefNo.Text = "";
            }

        }
        else if (ddlOption.Text == "UPLD")
        {
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
            lblOptionError.Text = string.Empty;
            lblOptionMessage.Text = string.Empty;
            Span1.InnerHtml = "";
            pnlDetails.Visible = true;
            pnlUpload.Visible = true;
            pnlCarDetails.Visible = false;
            pnlPayment.Visible = false;
            pnlApplicationCancel.Visible = false;
            pnlApplicationRetrieve.Visible = false;
            pnlUploadFileList.Visible = false;
            LoadUploadDocument();
        }
        else if (ddlOption.Text == "ACNL")
        {
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
            pnlDetails.Visible = true;
            pnlCarDetails.Visible = false;
            pnlPayment.Visible = false;
            pnlApplicationCancel.Visible = true;
            pnlApplicationRetrieve.Visible = false;
            pnlUploadFileList.Visible = false;

            DataSet _dsApplication = new DataSet();
            NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
            _dsApplication = _nonggpackagedb.GetCarDetails(Convert.ToInt64(txtCarId.Text.Trim()), Convert.ToInt64(txtUserId.Text.Trim()));
            if (_dsApplication != null && _dsApplication.Tables.Count > 2 && _dsApplication.Tables[2].Rows.Count > 0)
            {
                btnApplicationCancel.Enabled = true;
                lblOptionError.Text = string.Empty;
                lblOptionMessage.Text = string.Empty;
            }
            else
            {
                pnlOptionMessage.Visible = true;
                btnApplicationCancel.Enabled = false;
                lblOptionError.Text = Resources.General.HaveNotSubmit;
            }
        }
        else if (ddlOption.Text == "RTRV")
        {
            lblOptionError.Text = string.Empty;
            lblOptionMessage.Text = string.Empty;
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
            pnlDetails.Visible = true;
            pnlCarDetails.Visible = false;
            pnlPayment.Visible = false;
            pnlApplicationCancel.Visible = false;
            pnlApplicationRetrieve.Visible = true;
            pnlUploadFileList.Visible = false;
        }
        else if (ddlOption.Text == "0")
        {
            lblOptionError.Text = string.Empty;
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',false);", true);
            pnlDetails.Visible = true;
            pnlCarDetails.Visible = false;
            pnlPayment.Visible = false;
            pnlApplicationCancel.Visible = false;
            pnlApplicationRetrieve.Visible = false;
            pnlUploadFileList.Visible = false;
        }
      
        lblLoadMessage.Text = string.Empty;
    }

    protected void ddlPaymentType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPaymentType.Text == "CCOL" || ddlPaymentType.Text == "CCIP")
        {
            pnlCreditCard.Visible = true;
        }
        else
        {
            pnlCreditCard.Visible = false;
            if (txtPaymentId.Text != string.Empty && Convert.ToInt64(txtPaymentId.Text.Trim()) == 0)
            {
                txtCardHolder.Text = "";
                txtIssuingBank.Text = "";
                txtCardNo1.Text = "";
                txtCardNo2.Text = "";
                txtCardNo3.Text = "";
                txtCardNo4.Text = "";
                ddlCardExpiryMonth.SelectedIndex = 0;
                ddlCardExpiryYear.SelectedIndex = 0;
                ddlCardType.SelectedIndex = 0;
                txtCVV.Text = "000";
            }
        }
        lblLoadMessage.Text = string.Empty;
    }

    protected void ddlPaymentOption_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPaymentOption.Text == "IP")
        {
            ddlPaymentType.Items.Clear();
            ddlPaymentType.Items.Add(new ListItem("Select", "-1"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.CreditcardiPay, "CCIP"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.CreditcardOnline, "CCOL"));
        }
        else
        {
            ddlPaymentType.Items.Clear();
            ddlPaymentType.Items.Add(new ListItem("Select", "-1"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.Cash, "CASH"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.BankIn, "BKTR"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.CreditcardiPay, "CCIP"));
            ddlPaymentType.Items.Add(new ListItem(Resources.CarInsurance.CreditcardOnline, "CCOL"));
        }
        ddlPaymentType_SelectedIndexChanged(null, null);
        
        lblLoadMessage.Text = string.Empty;
    }

    protected void btnOnlinePaySubmit_Click(object sender, EventArgs e)
    {
        lblPayError.Text = "";
        lblOnlinePayError.Text = "";
        Page.Validate("olpay");
        if (txtOnlineApproveStatus.Text != string.Empty && txtOnlineApproveStatus.Text == "1")
        {
            lblPayError.Text = Resources.General.AlreadyApproved;// "Already Approved";
            lblLoadMessage.Text = string.Empty;
            return;
        }
        lblLoadMessage.Text = string.Empty;
        if (Page.IsValid)
        {
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
               
                Int16 _Valid = 1;
                if (_Valid == 1)
                {
                    Int64 _result = -1;

                    Payments _payments = new Payments();
                    PaymentsDB _paymentsdb = new PaymentsDB();
                    txtPaymentId.Text = "0";
                    _payments.PaymentId = Convert.ToInt64(txtPaymentId.Text.Trim());
                    _payments.QuoteRefNo = lblPRefNo.Text;
                    _payments.CECarId = Convert.ToInt64(txtCarId.Text);
                    _payments.ProviderCompanyId = Convert.ToInt64(txtProviderId.Text.Trim());
                    _payments.RefCEUserId = Convert.ToInt64(txtUserId.Text);
                    _payments.AgentId = Convert.ToInt64(Session[General.UserId].ToString());
                    _payments.AdminId = Convert.ToInt64(Session[General.UserId].ToString());

                    _payments.CollectedAmount = Convert.ToSingle(txtOnlineAmount.Text);

                    _payments.TransactionType = 1;
                    _payments.PaymentOption = "FP";
                    if (txtOnlinePaymentType.Text.Trim().ToUpper() == "CREDITCARD")
                    {
                        _payments.PaymentType = "CCOL";
                        _payments.CardHolder = "XXXXXXXX";
                        _payments.IssuingBank = "BBL";
                        _payments.CreditCardNo = "XXXXXXXXXXXXXXXX";
                        _payments.CVV = "XXX";
                        _payments.CardExpiryMonth = "00";
                        _payments.CardExpiryYear = "0000";
                        _payments.CardType = " ";
                    }
                    else if (txtOnlinePaymentType.Text.Trim().ToUpper() == "BANKTRANSFER")
                    {
                        _payments.PaymentType = "BKTR";
                    }

                    _payments.ApproveType = 1;
                    _payments.PaymentRefNo = Server.HtmlEncode(txtOnlinePaymentRefNo.Text);
                    _payments.IsOnlinePayment = 1;
                    _payments.Status = true;
                    _result = _paymentsdb.Insert(_payments);
                    if (_result > 0)
                    {

                        string AgentEmail = "";
                        string strSql = "";
                        MyDatabase _db = new MyDatabase();
                        strSql = "SELECT UC.Info1 SMPTKey FROM tblCEContact UC INNER JOIN tblPayments PY ON PY.AgentId = UC.RefCEUserId WHERE PY.PaymentId  = " + txtPaymentId.Text;
                        DataTable _dtAgentId = _db.GetDataTable(strSql);
                        if (_dtAgentId != null && _dtAgentId.Rows.Count > 0)
                        {
                            string SMTPKey = _dtAgentId.Rows[0]["SMPTKey"].ToString();
                            AgentEmail = GetSMTPAccount(SMTPKey.ToLower());
                        }
                        SendApproveMailToAdmin(_payments.TransactionType, txtCustomerName.Text, txtOnlineAmount.Text, AgentEmail, 1);


                        grvPayment.Enabled = true;
                        txtPaymentId.Text = "0";
                        pnlPaymentInput.Visible = true;
                        btnOnlinePaySubmit.Visible = false;
                        btnOnlinePayDecline.Visible = false;
                     
                        lblOnlinePayError.Text = Resources.General.OnlinePaymentApprove;
                        

                        ClearPayFields();
                        DataSet _dsPayment = new DataSet();
                        _dsPayment = GetBrokerPremium();
                        if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
                        {
                            txtBalanceAmount.Text = "0";
                            txtTotalCollectedAmount.Text = "0";
                            txtTotalRefundAmount.Text = "0";
                            grvPayment.DataSource = _dsPayment.Tables[1];
                            grvPayment.DataBind();
                            txtPaymentId.Text = "0";
                            EnableDisable();
                            if (grvPayment.Rows.Count > 0)
                            {
                                //Sakthi 14 Jun 2012 -Start
                                chkRefund.Enabled = true;
                                //Sakthi 14 Jun 2012 -End
                                DataSet _dsPaymentAmount = new DataSet();
                                _dsPaymentAmount = GetPaymentAmounts();
                                if (_dsPaymentAmount != null && _dsPaymentAmount.Tables.Count > 0 && _dsPaymentAmount.Tables[0].Rows.Count > 0)
                                {
                                    txtBalanceAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["BalanceAmount"].ToString();
                                    txtTotalCollectedAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString();
                                    txtTotalRefundAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["RefundAmount"].ToString();
                                }
                                divPayList.Visible = true;
                            }
                            else
                            {
                                divPayList.Visible = false;
                            }
                        }
                        if (txtPaymentId.Text == "0")
                        {
                            chkRefund.Enabled = true;
                        }
                        else
                        {
                            chkRefund.Enabled = false;
                        }
                    }
                }
                else
                {
                    if (_Valid == 4)
                        lblOnlinePayError.Text = Resources.General.AmountExceedBalance;
                }
            }
            else
            {
                lblOnlinePayError.Text = Resources.Proposal.AccessDenied;
            }
        }
    }

    protected void btnOnlinePayDecline_Click(object sender, EventArgs e)
    {
        Int64 _result = -1;
        Int64 CECarId = Convert.ToInt64(txtCarId.Text);
        Int64 ProviderId = Convert.ToInt64(txtProviderId.Text.Trim());
        Int64 AgentId = Convert.ToInt64(Session[General.UserId].ToString());

        NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
        if (txtAppStatus.Text == "ONLINE")
        {
            _result = _nonggpackagedb.DeclineOnlinePayment(CECarId, ProviderId, AgentId);
        }
        else if (txtAppStatus.Text == "OFFLINE")
        {
            _result = _nonggpackagedb.DeclineNonGGOnlinePayment(CECarId, ProviderId, AgentId);
        }

        if (_result > 0)
        {

            string AgentEmail = "";
            string strSql = "";
            MyDatabase _db = new MyDatabase();
            strSql = "SELECT UC.Info1 SMPTKey FROM tblCEContact UC INNER JOIN tblPayments PY ON PY.AgentId = UC.RefCEUserId WHERE PY.PaymentId  = " + txtPaymentId.Text;
            DataTable _dtAgentId = _db.GetDataTable(strSql);
            if (_dtAgentId != null && _dtAgentId.Rows.Count > 0)
            {
                string SMTPKey = _dtAgentId.Rows[0]["SMPTKey"].ToString();
               
                AgentEmail = GetSMTPAccount(SMTPKey.ToLower());
            }
            SendApproveMailToAdmin(1, txtCustomerName.Text, txtOnlineAmount.Text, AgentEmail, 0);


            grvPayment.Enabled = true;
            txtPaymentId.Text = "0";
            pnlPaymentInput.Visible = true;
            btnOnlinePaySubmit.Visible = false;
            btnOnlinePayDecline.Visible = false;
          
            lblOnlinePayError.Text = Resources.General.OnlinePaymentDecline;
        }
    }

    protected void btnPaySubmit_Click(object sender, EventArgs e)
    {
        lblPayError.Text = "";
        ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "CheckPaymentType();", true);
        Page.Validate("pay");
        if (txtApproveStatus.Text != string.Empty && txtApproveStatus.Text == "1" && txtPaymentId.Text != string.Empty && txtPaymentId.Text != "0")
        {
            lblPayError.Text = Resources.General.AlreadyApproved;// "Already Approved";
            lblLoadMessage.Text = string.Empty;
            return;
        }
        EnablePaymentOnOff();
        lblLoadMessage.Text = string.Empty;
        if (Page.IsValid)
        {
            if (SubmitPaymentPermission())
            {
                Int16 _Valid = AmountExceedValid(1);
                if (_Valid == 1)
                {
                    Int64 _result = -1;

                    Payments _payments = new Payments();
                    PaymentsDB _paymentsdb = new PaymentsDB();

                    _payments.PaymentId = Convert.ToInt64(txtPaymentId.Text.Trim());
                    _payments.QuoteRefNo = lblPRefNo.Text;
                    _payments.CECarId = Convert.ToInt64(txtCarId.Text);
                    _payments.ProviderCompanyId = Convert.ToInt64(txtProviderId.Text.Trim());
                    _payments.RefCEUserId = Convert.ToInt64(txtUserId.Text);
                    if (_payments.PaymentId == 0)
                    {
                        _payments.AgentId = Convert.ToInt64(Session[General.UserId].ToString());
                        _payments.AdminId = 0;
                    }
                    else
                    {
                        _payments.AgentId = 0;
                        _payments.AdminId = Convert.ToInt64(Session[General.UserId].ToString());
                    }

                    _payments.CollectedAmount = Convert.ToSingle(txtAmount.Text);
                    if (chkRefund.Checked)
                    {
                        _payments.TransactionType = 2;
                    }
                    else
                    {
                        _payments.TransactionType = 1;
                        _payments.PaymentOption = ddlPaymentOption.Text;
                        _payments.PaymentType = ddlPaymentType.Text;
                        _payments.CardHolder = Server.HtmlEncode(txtCardHolder.Text);
                        _payments.IssuingBank = Server.HtmlEncode(txtIssuingBank.Text);
                        if (_payments.PaymentId > 0)
                        {
                            _payments.CreditCardNo = txtCardNo1.Text.Trim() + "XXXXXXXX" + txtCardNo4.Text.Trim();
                            _payments.CVV = "XXX";
                        }
                        else
                        {
                            _payments.CreditCardNo = txtCardNo1.Text.Trim() + txtCardNo2.Text.Trim() + txtCardNo3.Text.Trim() + txtCardNo4.Text.Trim();
                            _payments.CVV = txtCVV.Text;
                        }
                        _payments.CardExpiryMonth = ddlCardExpiryMonth.Text;
                        _payments.CardExpiryYear = ddlCardExpiryYear.Text;
                        _payments.CardType = ddlCardType.Text;
                    }
                    if (chkApprove.Checked)
                    {
                        _payments.ApproveType = 1;
                    }
                    else
                    {
                        _payments.ApproveType = 0;
                    }

                    _payments.PaymentRefNo = Server.HtmlEncode(txtPaymentRefNo.Text);
                    _payments.IsOnlinePayment = 0;
                    _payments.Status = true;
                    _result = _paymentsdb.Insert(_payments);
                    if (_result > 0)
                    {
                        if (chkApprove.Checked && txtPaymentId.Text != string.Empty)
                        {
                            string AgentEmail = "";
                            string strSql = "";
                            MyDatabase _db = new MyDatabase();
                            strSql = "SELECT UC.Info1 SMPTKey FROM tblCEContact UC INNER JOIN tblPayments PY ON PY.AgentId = UC.RefCEUserId WHERE PY.PaymentId  = " + txtPaymentId.Text;
                            DataTable _dtAgentId = _db.GetDataTable(strSql);
                            if (_dtAgentId != null && _dtAgentId.Rows.Count > 0)
                            {
                                string SMTPKey = _dtAgentId.Rows[0]["SMPTKey"].ToString();
                                AgentEmail = GetSMTPAccount(SMTPKey.ToLower());
                            }
                            SendApproveMailToAdmin(_payments.TransactionType, txtCustomerName.Text, txtAmount.Text, AgentEmail, _payments.ApproveType);
                        }
                        if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "100")
                        {
                            string mailBody = "";
                            string _emailTitle = "";
                            string _toemail = "";
                            string _ccemail = "";
                            string _bccemail = "";
                            _emailTitle = "[" + lblUpRefNo.Text + "] " + Resources.CarInsurance.Payment + "  [" + txtPlateNumber.Text + "]";
                            mailBody = Resources.General.CustomerName + " : " + txtCustomerName.Text + "<br/><br/>";
                            mailBody += Resources.General.ReferenceNo + " : " + lblUpRefNo.Text + "<br/><br/>";
                            mailBody += Resources.CarInsurance.PaymentType + " : " + ddlPaymentType.SelectedItem.Text + "<br/><br/>";
                            mailBody += Resources.CarInsurance.Amount + " : " + txtAmount.Text + "<br/><br/>";
                            if (_payments.TransactionType == 1)
                            {
                                mailBody += Resources.General.TransactionType + " : " + Resources.CarInsurance.Payment + "<br/><br/>";
                            }
                            else if (_payments.TransactionType == 2)
                            {
                                mailBody += Resources.General.TransactionType + " : " + Resources.CarInsurance.Refund + "<br/><br/>";
                            }
                            mailBody += Resources.General.Broker + " : " + Session[CE.Global.General.UserName].ToString();
                            mailBody += "";
                            _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CASH");
                            _toemail += CE.Configuration.MyConfigurationManager.GetAppSettingValue("ADMIN");
                           
                            if (Session[General.UserRole].ToString() == "100")
                            {
                                _ccemail += Session[General.SMTPReplyTo].ToString();
                            }
                            _bccemail = "";

                          

                            MyMailManager.SendGGMail(ConfigurationManager.AppSettings["GGFormsSMTPAccount"].ToString(), ConfigurationManager.AppSettings["GGFormsSMTPAuthCode"].ToString(), _toemail, _ccemail, _bccemail, _emailTitle, mailBody, Session[General.SMTPReplyTo].ToString());
                        }

                        ClearPayFields();
                        DataSet _dsPayment = new DataSet();
                        _dsPayment = GetBrokerPremium();
                        if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
                        {
                            txtBalanceAmount.Text = "0";
                            txtTotalCollectedAmount.Text = "0";
                            txtTotalRefundAmount.Text = "0";
                            grvPayment.DataSource = _dsPayment.Tables[1];
                            grvPayment.DataBind();
                            txtPaymentId.Text = "0";
                            EnableDisable();
                            if (grvPayment.Rows.Count > 0)
                            {
                                //Sakthi 14 Jun 2012 -Start
                                chkRefund.Enabled = true;
                                //Sakthi 14 Jun 2012 -End
                                DataSet _dsPaymentAmount = new DataSet();
                                _dsPaymentAmount = GetPaymentAmounts();
                                if (_dsPaymentAmount != null && _dsPaymentAmount.Tables.Count > 0 && _dsPaymentAmount.Tables[0].Rows.Count > 0)
                                {
                                    txtBalanceAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["BalanceAmount"].ToString();
                                    txtTotalCollectedAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString();
                                    txtTotalRefundAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["RefundAmount"].ToString();
                                }
                                divPayList.Visible = true;
                            }
                            else
                            {
                                divPayList.Visible = false;
                            }
                        }
                        if (txtPaymentId.Text == "0")
                        {
                            chkRefund.Enabled = true;
                        }
                        else
                        {
                            chkRefund.Enabled = false;
                        }
                    }
                }
                else
                {
                    if (_Valid == 2)
                        lblPayError.Text = Resources.CarInsurance.ExceedCollected;
                    else if (_Valid == 3)
                        lblPayError.Text = Resources.CarInsurance.ExceedPremium;
                }
            }
            else
            {
                lblPayError.Text = Resources.Proposal.AccessDenied;
            }
        }
    }

    protected void btnPayDecline_Click(object sender, EventArgs e)
    {
        if (txtCarId.Text != string.Empty && txtPaymentId.Text != string.Empty)
        {
            if (txtStatus.Text != string.Empty && txtStatus.Text.ToUpper() != "TRUE" && txtPaymentId.Text != string.Empty && txtPaymentId.Text != "0")
            {
                lblPayError.Text = Resources.General.AlreadyDeclined;// "Already Declined";
                lblLoadMessage.Text = string.Empty;
                return;
            }
            if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() == "300")
            {
                Int64 _result = -1;
                Int64 CECarId = Convert.ToInt64(txtCarId.Text);
                Int64 AdminId = Convert.ToInt64(Session[General.UserId].ToString());
                Int64 PaymentId = Convert.ToInt64(txtPaymentId.Text);

                NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
                _result = _nonggpackagedb.DeclineNonGGPayment(CECarId, AdminId, PaymentId);

                if (_result > 0)
                {
                    if (txtPaymentId.Text != string.Empty)
                    {
                        Int16 TransactionType = 0;
                        if (chkRefund.Checked)
                        {
                            TransactionType = 2;
                        }
                        else
                        {
                            TransactionType = 1;
                        }
                        string AgentEmail = "";
                        string strSql = "";
                        MyDatabase _db = new MyDatabase();
                        strSql = "SELECT UC.Info1 SMPTKey FROM tblCEContact UC INNER JOIN tblPayments PY ON PY.AgentId = UC.RefCEUserId WHERE PY.PaymentId  = " + txtPaymentId.Text;
                        DataTable _dtAgentId = _db.GetDataTable(strSql);
                        if (_dtAgentId != null && _dtAgentId.Rows.Count > 0)
                        {
                            string SMTPKey = _dtAgentId.Rows[0]["SMPTKey"].ToString();

                            AgentEmail = GetSMTPAccount(SMTPKey.ToLower());
                        }
                        SendApproveMailToAdmin(TransactionType, txtCustomerName.Text, txtAmount.Text, AgentEmail, 0);
                    }

                    ClearPayFields();
                    DataSet _dsPayment = new DataSet();
                    _dsPayment = GetBrokerPremium();
                    if (_dsPayment != null && _dsPayment.Tables.Count > 1 && _dsPayment.Tables[1].Rows.Count > 0)
                    {
                        txtBalanceAmount.Text = "0";
                        txtTotalCollectedAmount.Text = "0";
                        txtTotalRefundAmount.Text = "0";
                        grvPayment.DataSource = _dsPayment.Tables[1];
                        grvPayment.DataBind();
                        txtPaymentId.Text = "0";
                        EnableDisable();
                        if (grvPayment.Rows.Count > 0)
                        {
                            chkRefund.Enabled = true;
                            DataSet _dsPaymentAmount = new DataSet();
                            _dsPaymentAmount = GetPaymentAmounts();
                            if (_dsPaymentAmount != null && _dsPaymentAmount.Tables.Count > 0 && _dsPaymentAmount.Tables[0].Rows.Count > 0)
                            {
                                txtBalanceAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["BalanceAmount"].ToString();
                                txtTotalCollectedAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString();
                                txtTotalRefundAmount.Text = _dsPaymentAmount.Tables[0].Rows[0]["RefundAmount"].ToString();
                            }
                            divPayList.Visible = true;
                        }
                        else
                        {
                            divPayList.Visible = false;
                        }
                    }
                    if (txtPaymentId.Text == "0")
                    {
                        chkRefund.Enabled = true;
                    }
                    else
                    {
                        chkRefund.Enabled = false;
                    }
                }
            }
            else
            {
                lblPayError.Text = Resources.Proposal.AccessDenied;
            }
        }
    }

    protected void btnPayNew_Click(object sender, EventArgs e)
    {
        ClearPayFields();
        EnablePaymentOnOff();
    }

    protected void btnApplicationCancel_Click(object sender, EventArgs e)
    {
        txtLastQuoteRefNo.Text = lblUpRefNo.Text.Trim();
        Page.Validate("appcancel");
        if (Page.IsValid)
        {
            Int64 _result = -1;
            Int16 Step = 1;
            Int64 CECarId = Convert.ToInt64(txtCarId.Text);
            Int64 ProviderId = Convert.ToInt64(txtProviderId.Text.Trim());
            string Remarks = Server.HtmlEncode(txtRemark.Text.Trim());
            Int64 AgentId = Convert.ToInt64(Session[General.UserId].ToString());

            NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
            _result = _nonggpackagedb.UpdateApplicationCancelStatus(CECarId, ProviderId, AgentId, Step, Remarks);
            if (_result > 0)
            {
                pnlApplicationCancel.Visible = false;
                
                lblOptionMessage.Text = Resources.CarInsurance.SuccessCancelApplication;
                pnlOptionMessage.Visible = true;

               
                txtCancelStatus.Text = "1";
                ddlOption.Items.Clear();
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Select, "0"));
                ddlOption.Items.Add(new ListItem(Resources.CarInsurance.Retrieve, "RTRV"));
                ddlOption.SelectedIndex = 0;
                
                ddlOption.SelectedIndex = 0;
                ddlOption_SelectedIndexChanged(null, null);
            }
        }
    }

    protected void btnApplicationRetrieve_Click(object sender, EventArgs e)
    {
        txtLastQuoteRefNo.Text = lblUpRefNo.Text.Trim();
        
        if (Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() != "100")
        {
            if (CheckSelectedItem(lblUpRefNo.Text.ToUpper()))
            {
                Int64 _result = -1;
                Int16 Step = 2;
                Int64 CECarId = Convert.ToInt64(txtCarId.Text);
                Int64 ProviderId = Convert.ToInt64(txtProviderId.Text.Trim());
                Int64 AgentId = Convert.ToInt64(Session[General.UserId].ToString());

                NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
                _result = _nonggpackagedb.UpdateApplicationRetrieveStatus(CECarId, ProviderId, AgentId, Step, lblUpRefNo.Text.ToUpper());
                if (_result > 0)
                {
                    pnlApplicationRetrieve.Visible = false;
                    lblOptionMessage.Text = Resources.CarInsurance.SuccessRetrieveApplication;
                    pnlOptionMessage.Visible = true;
                   
                    txtCancelStatus.Text = "0";
                    LoadOption();
                    ddlOption.SelectedIndex = 0;
                    ddlOption_SelectedIndexChanged(null, null);
                }
            }
            else
            {
                lblSearchMessage.Text = Resources.General.CheckRefNo;
            }
        }
        else
        {
            lblOptionMessage.Text = Resources.Proposal.AccessDenied;
            pnlOptionMessage.Visible = true;
        }
    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        Span1.InnerHtml = "";
        Page.Validate("upload");
        if (Page.IsValid)
        {
            if (FileUpLoad1.HasFile)
            {
                int DocNo = 1;
                Int64 _fileSize = 0;
                string _todaydate = dateTimeNow.ToString("ddMMMMyyyy");
                string _filePath = GetPdfFilePath("documents");
                string _IsPDF = Path.GetExtension(FileUpLoad1.FileName);
                string _OriginalFile = Path.GetFileName(FileUpLoad1.FileName);
                string _fileName = ddlFileUploadType.SelectedItem.Text + "_" + txtCarId.Text.Trim() + "_" + GetRandomNo() + "_" + _todaydate;
                _fileName = _fileName.Replace(' ', '_');
                _fileSize = FileUpLoad1.FileContent.Length;
                if (_IsPDF.ToUpper() == ".PDF")
                {
                    if ((_fileSize / 1024) < 1025)
                    {
                        try
                        {
                            FileUpLoad1.PostedFile.SaveAs(_filePath + _fileName + ".pdf");

                            Int64 _uploadResult = 0;
                            
                            string _DocRefNo = "";
                            DateTime _tDate = new DateTime();
                            _tDate = dateTimeNow;
                            _DocRefNo = _tDate.Year.ToString("0000") + _tDate.Month.ToString("00") + _tDate.Day.ToString("00") + _tDate.Hour.ToString("00") + _tDate.Minute.ToString("00") + _tDate.Second.ToString("00");
                            _DocRefNo += txtCarId.Text.Trim() + "A" + Session[General.UserId].ToString();
                            CarFileUpload _carfileupload = new CarFileUpload();
                            CarFileUploadDB _carfileuploaddb = new CarFileUploadDB();

                            _carfileupload.CarId = Convert.ToInt64(txtCarId.Text.Trim());
                            _carfileupload.ProviderCompanyId = Convert.ToInt64(txtProviderId.Text.Trim());
                            _carfileupload.InsuranceType = "CI";
                            _carfileupload.AgentId = Convert.ToInt64(Session[General.UserId].ToString());
                            _carfileupload.DocRefNo = _DocRefNo;
                            _carfileupload.DocumentNo = DocNo;
                            _carfileupload.FileTypeId = Convert.ToInt64(ddlFileUploadType.Text);
                            _carfileupload.FileName = _filePath + _fileName.ToString() + ".pdf";
                            _carfileupload.OriginalName = _OriginalFile.ToString();
                            _carfileupload.Status = true;
                            _carfileupload.TotalFiles = DocNo;
                            _uploadResult = _carfileuploaddb.InsertNonGG(_carfileupload);

                            if (_uploadResult > 0)
                            {
                                
                                txtChassisNumber.Text = "";

                                pnlOptionMessage.Visible = true;
                                lblOptionMessage.Text = Resources.General.SuccessfullyUpdated;
                                
                                ddlFileUploadType.SelectedIndex = 0;
                                ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
                                LoadUploadDocument();
                            }
                            else
                            {
                                Span1.InnerHtml = Resources.General.UploadFileNameSaveFailed;
                                ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
                            }
                        }
                        catch (Exception ex)
                        {
                            Span1.InnerHtml = Resources.General.FileUploadFailed;
                            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
                        }
                    }
                    else
                    {
                        Span1.InnerHtml = Resources.General.Maximum1MB;
                        ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
                    }
                }
                else
                {
                    Span1.InnerHtml = Resources.General.PDFformat;
                    ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
                }
            }
            else
            {
                Span1.InnerHtml = Resources.General.ChooseDocument;
                ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
            }
        }
        else
        {
            Span1.InnerHtml = Resources.General.ChooseDocument;
            ScriptManager.RegisterStartupScript(ddlOption, ddlOption.GetType(), Guid.NewGuid().ToString(), "ShowHideDiv('divUpload',true);", true);
        }
    }

    protected void grvPayment_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblPayError.Text = "";
        txtApproveStatus.Text = "0";
        if (grvPayment.Rows.Count > 0)
        {
            if (grvPayment.SelectedIndex >= 0)
            {
                btnPayDecline.Visible = true;
                btnPaySubmit.Text = Resources.CarInsurance.Approve;
                GridViewRow row = grvPayment.SelectedRow;
                txtPaymentId.Text = grvPayment.SelectedDataKey[0].ToString();
                txtStatus.Text = grvPayment.SelectedDataKey[12].ToString();
                txtAmount.Text = row.Cells[3].Text;
                txtAmount.ReadOnly = true;
               
                rfvCVV.Enabled = false;
                revCVV.Enabled = false;
                EnableDisable();
                if (grvPayment.SelectedDataKey[3].ToString() == "1")
                {
                    chkRefund.Checked = false;
                    ddlPaymentOption.Text = grvPayment.SelectedDataKey[1].ToString();
                    ddlPaymentOption_SelectedIndexChanged(null, null);
                    ddlPaymentType.Text = grvPayment.SelectedDataKey[2].ToString();
                    ddlPaymentType_SelectedIndexChanged(null, null);
                }
                else
                {
                    chkRefund.Checked = true;
                }
                if (grvPayment.SelectedDataKey[4].ToString() == "1")
                {
                   
                    btnPaySubmit.Enabled = false;
                    btnPayDecline.Visible = false;
                }
                else
                {
                   
                    btnPaySubmit.Enabled = true;
                }
                txtApproveStatus.Text = grvPayment.SelectedDataKey[4].ToString();
                chkApprove.Checked = true;
                chkApprove.Enabled = false;
                
                if (chkRefund.Checked == false)
                {
                    if (ddlPaymentType.Text == "CCIP" || ddlPaymentType.Text == "CCOL")
                    {
                        pnlCreditCard.Visible = true;
                        txtCardHolder.Text = grvPayment.SelectedDataKey[5].ToString();
                        txtIssuingBank.Text = grvPayment.SelectedDataKey[6].ToString();
                        if (txtOnlineApproveStatus.Text != string.Empty && txtOnlineApproveStatus.Text != "1")
                        {
                            ddlCardExpiryMonth.Text = grvPayment.SelectedDataKey[7].ToString();
                            ddlCardExpiryYear.Text = grvPayment.SelectedDataKey[8].ToString();
                            ddlCardType.Text = grvPayment.SelectedDataKey[9].ToString();
                        }
                        txtCVV.Text = grvPayment.SelectedDataKey[10].ToString();
                        string CC = row.Cells[2].Text;
                        for (int i = 0; i < 4; i++)
                        {
                            if (i == 0)
                            {
                                txtCardNo1.Text = CC.Substring(0, 4);
                            }
                            if (i == 1)
                            {
                                txtCardNo2.Text = CC.Substring(4, 4);
                            }
                            if (i == 2)
                            {
                                txtCardNo3.Text = CC.Substring(8, 4);
                            }
                            if (i == 3)
                            {
                                txtCardNo4.Text = CC.Substring(12, 4);
                            }
                        }
                    }
                    else
                    {
                        pnlCreditCard.Visible = false;
                        txtCardNo1.Text = "";
                        txtCardNo2.Text = "";
                        txtCardNo3.Text = "";
                        txtCardNo4.Text = "";
                        txtCardHolder.Text = "";
                        txtIssuingBank.Text = "";
                        ddlCardExpiryMonth.SelectedIndex = 0;
                        ddlCardExpiryYear.SelectedIndex = 0;
                        ddlCardType.SelectedIndex = 0;
                        txtCVV.Text = "000";
                    }
                }
                else
                {
                    pnlCreditCard.Visible = false;
                    txtCardNo1.Text = "";
                    txtCardNo2.Text = "";
                    txtCardNo3.Text = "";
                    txtCardNo4.Text = "";
                    txtCardHolder.Text = "";
                    txtIssuingBank.Text = "";
                    ddlCardExpiryMonth.SelectedIndex = 0;
                    ddlCardExpiryYear.SelectedIndex = 0;
                    ddlCardType.SelectedIndex = 0;
                    txtCVV.Text = "000";
                    ddlPaymentType.SelectedIndex = 0;
                    ddlPaymentOption.SelectedIndex = 0;
                }
                EnablePaymentOnOff();
                txtPaymentRefNo.Text = grvPayment.SelectedDataKey[11].ToString();

                if (txtPaymentId.Text == "0")
                {
                    chkRefund.Enabled = true;
                }
                else
                {
                    chkRefund.Enabled = false;
                }
            }
            else
            {
                txtPaymentId.Text = "0";
                btnPaySubmit.Text = Resources.General.Submit;
                EnableDisable();
            }
        }
        else
        {
            txtPaymentId.Text = "0";
            btnPaySubmit.Text = Resources.General.Submit;
            EnableDisable();
        }
    }

    protected void grvPayment_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string _Approve = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ApproveType"));
            string _Refund = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Transaction"));
            
            if (_Approve == "1")
            {
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }

            if (_Refund.ToUpper() == "REFUND")
            {
                e.Row.Cells[1].ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                e.Row.Cells[1].ForeColor = System.Drawing.Color.Green;
            }
        }
        
    }

    

    protected void grvFileUpload_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Span1.InnerHtml = "";
        if (e.CommandName.Equals("MyDelete"))
        {
            if (e.CommandArgument != null)
            {
                Int64 _FileId = 0;
                Int64 _CECarId = 0;
                Int64 _AgentId = 0;
                _FileId = Convert.ToInt64(e.CommandArgument);
                _CECarId = Convert.ToInt64(txtCarId.Text);
                _AgentId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());

                MyDatabase _db = new MyDatabase();
                SortedList _paraList = new SortedList();
                _paraList.Add("@FileId", _FileId);
                _paraList.Add("@CECarId", _CECarId);
                _paraList.Add("@AgentId", _AgentId);
                int _effCount = _db.ExecuteNonSqlSP("sprocCXCRMNonGGUploadCarFileDeleteSingleItem", _paraList);
                if (_effCount > 0)
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Delete was successful.');", true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Delete failed.');", true);
                }
                GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
                Label lblPath = (Label)row.FindControl("lblPath");
                MyIO _myIO = new MyIO();
                _myIO.DeleteFile(lblPath.Text);
                LoadUploadDocument();
            }
        }
    }

    protected void grvFileUpload_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink hplk = (HyperLink)e.Row.FindControl("hplDownLoad");
            Label Path = (Label)e.Row.FindControl("lblPath");

            if (hplk != null)
            {
                hplk.NavigateUrl = "DownLoad/UploadNonGGHandler.ashx?FileName=" + Path.Text;
            }
        }
    }

    private bool SaveDriverDetails()
    {
        bool _result = false;
        NonGGCarDriver _nonggcardriver = new NonGGCarDriver();
        NonGGCarDriverDB _nonggcardriverdb = new NonGGCarDriverDB();

        if (ddlNamedDriver.Text != "0")
        {
            int _drivercount = Convert.ToInt32(ddlNamedDriver.Text);
            int _insertcount = 0;

            for (int i = 1; i <= _drivercount; i++)
            {
                if (Session[CE.Global.General.UserId] != null)
                {
                    _nonggcardriver.AgentId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _nonggcardriver.AgentId = 0;
                }
                _nonggcardriver.RefCEUserId = Convert.ToInt64(txtUserId.Text);
                _nonggcardriver.CECarId = Convert.ToInt64(txtCarId.Text);
                if (i == 1)
                {
                    _nonggcardriver.CarDriverId = Convert.ToUInt32(txtDriverId1.Text);
                    _nonggcardriver.FullName = Server.HtmlEncode(txtDriverFirst.Text.Trim());
                    DateTime _dtDriver1DOB = new DateTime(Convert.ToInt32(ddlDriver1DOBYear.Text), Convert.ToInt32(ddlDriver1DOBMonth.Text), Convert.ToInt32(ddlDriver1DOBDay.Text));
                    _nonggcardriver.DOB = _dtDriver1DOB;
                    _nonggcardriver.IDNo = Server.HtmlEncode(txtDriver1IDNo.Text.Trim());
                    _nonggcardriver.DrivingLicenseNumber = Server.HtmlEncode(txtDriver1LicenseNo.Text.Trim());
                    _nonggcardriver.Status = true;
                }
                else if (i == 2)
                {
                    _nonggcardriver.CarDriverId = Convert.ToUInt32(txtDriverId2.Text); ;
                    _nonggcardriver.FullName = Server.HtmlEncode(txtDriverTwo.Text.Trim());
                    DateTime _dtDriver2DOB = new DateTime(Convert.ToInt32(ddlDriver2DOBYear.Text), Convert.ToInt32(ddlDriver2DOBMonth.Text), Convert.ToInt32(ddlDriver2DOBDay.Text));
                    _nonggcardriver.DOB = _dtDriver2DOB;
                    _nonggcardriver.IDNo = Server.HtmlEncode(txtDriver2IDNo.Text.Trim());
                    _nonggcardriver.DrivingLicenseNumber = Server.HtmlEncode(txtDriver2LicenseNo.Text.Trim());
                    _nonggcardriver.Status = true;
                }
                if (_nonggcardriverdb.Insert(_nonggcardriver) > 0)
                {
                    _insertcount++;
                    _result = true;
                }
            }
            _nonggcardriverdb = null;
            _nonggcardriver = null;
        }
        return _result;
    }

    private string GetExcelFilePath(Int64 ProviderCompanyId, string QuoteRefNo)
    {
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NonGGFileOutputPath").ToString();
        string _provider = CE.Global.General.GetProvider(ProviderCompanyId);
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
        string _currentMonth = dateTimeNow.ToString("yyyyMMM");
        string _todaydate = dateTimeNow.ToString("yyyyMMMdd");
        _filePath += "exceloutput\\" + _provider + "\\";
        if (!_myIO.CheckDirectory(_filePath + _currentMonth))
        {
            if (_myIO.CreateDirectory(_filePath, _currentMonth))
            {
                _filePath += _currentMonth + "\\";
            }
        }
        else
        {
            _filePath += _currentMonth + "\\";
        }

        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        if (!_myIO.CheckDirectory(_filePath + QuoteRefNo))
        {
            if (_myIO.CreateDirectory(_filePath, QuoteRefNo))
            {
                _filePath += QuoteRefNo + "\\";
            }
        }
        else
        {
            _filePath += QuoteRefNo + "\\";
        }
        return _filePath;
    }

    private string GetPdfFilePath(Int64 ProviderCompanyId, string QuoteRefNo)
    {
        //Currently Not Use=ing
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NonGGFileOutputPath").ToString();
        string _provider = CE.Global.General.GetProvider(ProviderCompanyId);
        string _currentMonth = dateTimeNow.ToString("yyyyMMM");
        string _todaydate = dateTimeNow.ToString("yyyyMMMdd");
        _filePath += "upload\\" + _provider + "\\";
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();
        if (!_myIO.CheckDirectory(_filePath + _currentMonth))
        {
            if (_myIO.CreateDirectory(_filePath, _currentMonth))
            {
                _filePath += _currentMonth + "\\";
            }
        }
        else
        {
            _filePath += _currentMonth + "\\";
        }

        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        if (!_myIO.CheckDirectory(_filePath + QuoteRefNo))
        {
            if (_myIO.CreateDirectory(_filePath, QuoteRefNo))
            {
                _filePath += QuoteRefNo + "\\";
            }
        }
        else
        {
            _filePath += QuoteRefNo + "\\";
        }
        return _filePath;
    }

    private string GetPdfFilePath(string FileType)
    {
        string _filePath = CE.Configuration.MyConfigurationManager.GetAppSettingValue("NonGGFileOutputPath").ToString();
        _filePath += "upload\\carinsurance\\";
        CE.InputOut.MyIO _myIO = new CE.InputOut.MyIO();

        string _curYear = dateTimeNow.ToString("yyyy");
        if (!_myIO.CheckDirectory(_filePath + _curYear))
        {
            if (_myIO.CreateDirectory(_filePath, _curYear))
            {
                _filePath += _curYear + "\\";
            }
        }
        else
        {
            _filePath += _curYear + "\\";
        }

        string _curMonth = dateTimeNow.ToString("MMMM");
        if (!_myIO.CheckDirectory(_filePath + _curMonth))
        {
            if (_myIO.CreateDirectory(_filePath, _curMonth))
            {
                _filePath += _curMonth + "\\";
            }
        }
        else
        {
            _filePath += _curMonth + "\\";
        }

        string _todaydate = dateTimeNow.ToString("ddMMMMyyyy");
        if (!_myIO.CheckDirectory(_filePath + _todaydate))
        {
            if (_myIO.CreateDirectory(_filePath, _todaydate))
            {
                _filePath += _todaydate + "\\";
            }
        }
        else
        {
            _filePath += _todaydate + "\\";
        }

        string _quotes = FileType.ToString() + "_" + _todaydate;
        if (!_myIO.CheckDirectory(_filePath + _quotes))
        {
            if (_myIO.CreateDirectory(_filePath, _quotes))
            {
                _filePath += _quotes + "\\";
            }
        }
        else
        {
            _filePath += _quotes + "\\";
        }

        return _filePath;
    }

    public void LoadUploadDocument()
    {
        MyDatabase _db = new MyDatabase("GG_CRMDBConnectionString");
        string _spName = "sprocCXCRMNonGGCarFileUploadDetailSelectItemList";
        string Language = "EN";
        if (lblLangOption.Text == "1")
            Language = "TH";
        SortedList _spara = new SortedList();
        _spara.Add("@CECarId", Convert.ToInt64(txtCarId.Text));
        _spara.Add("@ProviderCompanyId", Convert.ToInt64(txtProviderId.Text));
        _spara.Add("@Language", Language);
        DataSet _dsUploadDocument = new DataSet();
        _dsUploadDocument = _db.GetDataSet(_spName, _spara);
        if (_dsUploadDocument != null && _dsUploadDocument.Tables.Count > 3 && _dsUploadDocument.Tables[3].Rows.Count > 0)
        {
            grvFileUpload.Visible = true;
            grvFileUpload.DataSource = _dsUploadDocument.Tables[3];
            grvFileUpload.DataBind();
            if (grvFileUpload.Rows.Count > 0)
            {
                divFileList.Visible = true;
                pnlUploadFileList.Visible = true;
            }
            else
            {
                divFileList.Visible = false;
                pnlUploadFileList.Visible = false;
            }
        }
        else
        {
            grvFileUpload.DataSource = null;
            grvFileUpload.DataBind();
            divFileList.Visible = false;
        }
    }

    public void ExportGridView(string fileName, Label lblContent)
    {
        string attachment = "attachment; filename=" + fileName + ".xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        Response.Write(lblContent.Text);
        Response.End();
    }

    private string GetRandomNo()
    {
        string _RandomNo = "";
        int _randomlen = 6;
        Random random = new Random();
        for (int i = 0; i < _randomlen; i++)
        {
            _RandomNo += random.Next(0, 9).ToString();
        }
        return _RandomNo;
    }

    public void ClearFields()
    {
        txtStatus.Text = "TRUE";
        btnPayDecline.Visible = false;
        grvPayment.Enabled = true;
        pnlPaymentInput.Visible = true;
        btnPaySubmit.Text = Resources.General.Submit;
        lblLoadMessage.Text = string.Empty;
        lblPayError.Text = "";
        pnlCarDetails.Visible = false;
        
        pnlDetails.Visible = false;
        lblUpApplicantName.Text = "";
        lblUpInsurer.Text = "";
        lblUpPlanName.Text = "";
        lblUpPremium.Text = "";
        txtProviderId.Text = "";
        
        txtCarModelYear.Text = "";
        txtCarMakeModel.Text = "";
        txtSumInsured.Text = "";
        txtInsurancePremium.Text = "";
        txtCTPL.Text = "";
        txtTotalPremium.Text = "";
        txtCurrentInsurer.Text = "";
        
        txtChassisNumber.Text = "";
        txtPlateNumber.Text = "";
        txtRegistrationProvince.Text = "";
        ddlNCB.SelectedIndex = 0;
        txtInsuranceCompany.Text = "";
        txtPackage.Text = "";
        txtDriverFirst.Text = "";
        txtDriver1IDNo.Text = "";
        txtDriver1LicenseNo.Text = "";
        txtDriverTwo.Text = "";
        txtDriver2IDNo.Text = "";
        txtDriver2LicenseNo.Text = "";
        txtPrefix.Text = "";
        txtBeneficiary.Text = "";
        txtInsuredPerson.Text = "";
        txtContactNumber.Text = "";
        txtCurrentAddress.Text = "";
        txtSubDistrict.Text = "";
        txtStateProvince.Text = "";
        txtProvince.Text = "";
        txtPostalCode.Text = "";
        txtNewQuoteRefNo.Text = "";
        txtDriverId1.Text = "0";
        txtDriverId2.Text = "0";
    }

    public void LoadGarageType()
    {
        ddlGarageType.Items.Clear();
        ddlGarageType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Authorized, "1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Dealer, "2"));
    }

    public void LoadInsuranceType()
    {
        ddlInsuranceType.Items.Clear();
        ddlInsuranceType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOne, "10"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOneLowCost, "11"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassTwoPlus, "21"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThreePlus, "31"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThree, "30"));
    }

    public void LoadVehicleType()
    {
        ddlVehicleType.Items.Clear();
        ddlVehicleType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlVehicleType.Items.Add(new ListItem(Resources.CarInsurance.VehicleType_Private, "110"));
        ddlVehicleType.Items.Add(new ListItem(Resources.CarInsurance.VehicleType_Commercial, "210"));
    }

    private void LoadBrokerProvider()
    {
        DataTable _dtBrokerProvider = General.GetComboItem("BrokerProvider", true);
        if (_dtBrokerProvider != null && _dtBrokerProvider.Rows.Count > 0)
        {
            ddlBrokerProvider.DataSource = _dtBrokerProvider;
            ddlBrokerProvider.DataTextField = _dtBrokerProvider.Columns[0].ColumnName.ToString();
            ddlBrokerProvider.DataValueField = _dtBrokerProvider.Columns[1].ColumnName.ToString();
            ddlBrokerProvider.DataBind();
        }

        ddlBrokerProvider.Items.Insert(0, new ListItem("Select", "-1"));
      
    }

    public void LoadCarMake()
    {
        DataTable dtCarMake = General.GetComboItem(Resources.DBTable.CarMakeList, Resources.DBTable.CarMakeSortBy, false);

        if (dtCarMake != null && dtCarMake.Rows.Count > 0)
        {
            ddlCarMake.DataSource = dtCarMake;
            ddlCarMake.DataTextField = dtCarMake.Columns[0].ColumnName.ToString();
            ddlCarMake.DataValueField = dtCarMake.Columns[1].ColumnName.ToString();
            ddlCarMake.DataBind();
        }
        ddlCarMake.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    protected void ddlProvinceRegistration_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlProvinceRegistration.SelectedIndex > 0)
        {
            DataTable dtDistrict = General.GetComboItem(Resources.DBTable.DistrictList, "ProvinceID", ddlProvinceRegistration.SelectedValue, false);

            if (dtDistrict != null && dtDistrict.Rows.Count > 0)
            {
                ddlDistrict.DataSource = dtDistrict;
                ddlDistrict.DataTextField = dtDistrict.Columns[0].ColumnName.ToString();
                ddlDistrict.DataValueField = dtDistrict.Columns[1].ColumnName.ToString();
                ddlDistrict.DataBind();
            }
        }
        else
        {
            ddlDistrict.Items.Clear();
        }
        ddlDistrict.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadRegion()
    {
        DataTable dtCarMake = General.GetComboItem(Resources.DBTable.RegionList, false);

        if (dtCarMake != null && dtCarMake.Rows.Count > 0)
        {
            ddlRegion.DataSource = dtCarMake;
            ddlRegion.DataTextField = dtCarMake.Columns[0].ColumnName.ToString();
            ddlRegion.DataValueField = dtCarMake.Columns[1].ColumnName.ToString();
            ddlRegion.DataBind();
        }
        ddlRegion.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadProvince()
    {
        DataTable dtProvince = General.GetComboItem(Resources.DBTable.ProvinceList, Resources.DBTable.ProvinceSortBy, false);

        if (dtProvince != null && dtProvince.Rows.Count > 0)
        {
            ddlProvinceRegistration.DataSource = dtProvince;
            ddlProvinceRegistration.DataTextField = dtProvince.Columns[0].ColumnName.ToString();
            ddlProvinceRegistration.DataValueField = dtProvince.Columns[1].ColumnName.ToString();
            ddlProvinceRegistration.DataBind();
        }
        ddlProvinceRegistration.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadProvider()
    {
        DataTable dtProvider = General.GetComboItem(Resources.DBTable.ProviderCompany, Resources.DBTable.ProviderSortBy, false);

        if (dtProvider != null && dtProvider.Rows.Count > 0)
        {
            ddlBrokerProvider.DataSource = dtProvider;
            ddlBrokerProvider.DataTextField = dtProvider.Columns[0].ColumnName.ToString();
            ddlBrokerProvider.DataValueField = dtProvider.Columns[1].ColumnName.ToString();
            ddlBrokerProvider.DataBind();
        }
        ddlBrokerProvider.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadDate(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        for (int _date = 1; _date <= 31; _date++)
        {
            val = _date.ToString();
            if (_date < 10)
            {
                val = "0" + _date.ToString();
            }
            ddl.Items.Add(new ListItem(val, val));
        }
    }

    public void LoadMonth(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        
        string monthname = Resources.General.Select;
        for (int _month = 1; _month <= 12; _month++)
        {
            val = _month.ToString();
            if (_month < 10)
            {
                val = "0" + _month.ToString();
            }
            else
            {
                val = _month.ToString();
            }
            if (_month == 1)
            {
                monthname = Resources.MonthResource.January;
            }
            else if (_month == 2)
            {
                monthname = Resources.MonthResource.February;
            }
            else if (_month == 3)
            {
                monthname = Resources.MonthResource.March;
            }
            else if (_month == 4)
            {
                monthname = Resources.MonthResource.April;
            }
            else if (_month == 5)
            {
                monthname = Resources.MonthResource.May;
            }
            else if (_month == 6)
            {
                monthname = Resources.MonthResource.June;
            }
            else if (_month == 7)
            {
                monthname = Resources.MonthResource.July;
            }
            else if (_month == 8)
            {
                monthname = Resources.MonthResource.August;
            }
            else if (_month == 9)
            {
                monthname = Resources.MonthResource.September;
            }
            else if (_month == 10)
            {
                monthname = Resources.MonthResource.October;
            }
            else if (_month == 11)
            {
                monthname = Resources.MonthResource.November;
            }
            else if (_month == 12)
            {
                monthname = Resources.MonthResource.December;
            }
            
            ddl.Items.Add(new ListItem(monthname, val));
        }
    }

    public void LoadYear(DropDownList ddl, int start, int end)
    {
        string ddlval = "";
        string ddltxt = "";
        ddl.Items.Clear();
        for (int _year = start; _year <= end; _year++)
        {
            ddlval = _year.ToString();
            ddltxt = _year.ToString();
            if (lblLangOption.Text == "1")
            {
                ddltxt = (_year + 543).ToString();
            }
            ddl.Items.Add(new ListItem(ddltxt, ddlval));
        }
    }

    public void LoadOccupation()
    {
        DataTable dtOccupation = General.GetComboItem(Resources.CarInsurance.OccupationList, Resources.CarInsurance.OccupationSortBy, true);
        ddlOccupation.DataSource = dtOccupation;
        ddlOccupation.DataTextField = dtOccupation.Columns[0].ColumnName.ToString();
        ddlOccupation.DataValueField = dtOccupation.Columns[1].ColumnName.ToString();
        ddlOccupation.DataBind();
    }

    public void LoadFileUploadType()
    {
        string strKey = "";
        strKey = "EN.FileUploadType";
        if (lblLangOption.Text == "1")
        {
            strKey = "TH.FileUploadType";
        }
        DataTable dtFileUploadType = General.GetComboItem(strKey, true);
        ddlFileUploadType.DataSource = dtFileUploadType;
        ddlFileUploadType.DataTextField = dtFileUploadType.Columns[0].ColumnName.ToString();
        ddlFileUploadType.DataValueField = dtFileUploadType.Columns[1].ColumnName.ToString();
        ddlFileUploadType.DataBind();
        ddlFileUploadType.Items.Insert(0, new ListItem("Select", "-1"));
    }

    public void LoadDOB()
    {
        int intStartYear = dateTimeNow.Year - 90;
        int intEndYear = dateTimeNow.Year - 18;
        LoadDate(ddlDOBDay);
        LoadMonth(ddlDOBMonth);
        LoadYear(ddlDOBYear, intStartYear, intEndYear);

        LoadDate(ddlDriver1DOBDay);
        LoadMonth(ddlDriver1DOBMonth);
        LoadYear(ddlDriver1DOBYear, intStartYear, intEndYear);

        LoadDate(ddlDriver2DOBDay);
        LoadMonth(ddlDriver2DOBMonth);
        LoadYear(ddlDriver2DOBYear, intStartYear, intEndYear);
    }

    public void LoadCommanceDate()
    {
        int intStartYear = dateTimeNow.Year - 1;
        int intEndYear = dateTimeNow.Year + 1;
        LoadDate(ddlCommenceDay);
        LoadMonth(ddlCommenceMonth);
        LoadYear(ddlCommenceYear, intStartYear, intEndYear);
        LoadDate(ddlPolicyDay);
        LoadMonth(ddlPolicyMonth);
        LoadYear(ddlPolicyYear, intStartYear, intEndYear);
    }

    public void EnableOnOff(bool OnOff)
    {
        if (OnOff == true)
        {
            txtCarModelYear.ReadOnly = false;
            txtCarMakeModel.ReadOnly = false;
            txtCurrentInsurer.ReadOnly = false;
        }
        else if (OnOff == false)
        {
            txtCarModelYear.ReadOnly = true;
            txtCarMakeModel.ReadOnly = true;
            txtCurrentInsurer.ReadOnly = true;
        }
        ddlInsuranceType.Enabled = false;
        ddlVehicleType.Enabled = false;
        ddlGarageType.Enabled = false;
        ddlCommenceDay.Enabled = OnOff;
        ddlCommenceMonth.Enabled = OnOff;
        ddlCommenceYear.Enabled = OnOff;

        ddlPolicyDay.Enabled = OnOff;
        ddlPolicyMonth.Enabled = OnOff;
        ddlPolicyYear.Enabled = OnOff;

        ddlCTPL.Enabled = false;
        

        ddlDOBDay.Enabled = OnOff;
        ddlDOBMonth.Enabled = OnOff;
        ddlDOBYear.Enabled = OnOff;
        ddlGender.Enabled = OnOff;
        ddlOccupation.Enabled = OnOff;
        ddlNamedDriver.Enabled = OnOff;
    }

    public void EnablePaymentOnOff()
    {
        if (chkRefund.Checked)
        {
            rfvPaymentType.Enabled = false;
            rfvPaymentOption.Enabled = false;
            rfvCardHolder.Enabled = false;
            rfvIssuingBank.Enabled = false;
            rfvCardNo1.Enabled = false;
            revCardNo1.Enabled = false;
            rfvCardNo2.Enabled = false;
            revCardNo2.Enabled = false;
            rfvCardNo3.Enabled = false;
            revCardNo3.Enabled = false;
            rfvCardNo4.Enabled = false;
            revCardNo4.Enabled = false;
            rfvCardExpiryMonth.Enabled = false;
            rfvCardExpiryYear.Enabled = false;
            csvCCExpiredValid.Enabled = false;
            rfvCardType.Enabled = false;
            rfvCVV.Enabled = false;
            revCVV.Enabled = false;
        }
        else
        {
            rfvPaymentType.Enabled = true;
            rfvPaymentOption.Enabled = true;
            if (ddlPaymentType.Text == "CCOL" || ddlPaymentType.Text == "CCIP")
            {
                if (chkApprove.Checked)
                {
                    rfvCardHolder.Enabled = false;
                    rfvIssuingBank.Enabled = false;
                    rfvCardNo1.Enabled = false;
                    revCardNo1.Enabled = false;
                    rfvCardNo2.Enabled = false;
                    revCardNo2.Enabled = false;
                    rfvCardNo3.Enabled = false;
                    revCardNo3.Enabled = false;
                    rfvCardNo4.Enabled = false;
                    revCardNo4.Enabled = false;
                    rfvCardExpiryMonth.Enabled = false;
                    rfvCardExpiryYear.Enabled = false;
                    csvCCExpiredValid.Enabled = false;
                    rfvCardType.Enabled = false;
                    rfvCVV.Enabled = false;
                    revCVV.Enabled = false;
                }
                else
                {
                    rfvCardHolder.Enabled = true;
                    rfvIssuingBank.Enabled = true;
                    rfvCardNo1.Enabled = true;
                    revCardNo1.Enabled = true;
                    rfvCardNo2.Enabled = true;
                    revCardNo2.Enabled = true;
                    rfvCardNo3.Enabled = true;
                    revCardNo3.Enabled = true;
                    rfvCardNo4.Enabled = true;
                    revCardNo4.Enabled = true;
                    rfvCardExpiryMonth.Enabled = true;
                    rfvCardExpiryYear.Enabled = true;
                    csvCCExpiredValid.Enabled = true;
                    rfvCardType.Enabled = true;
                    rfvCVV.Enabled = true;
                    revCVV.Enabled = true;
                }
            }
            else
            {
                rfvCardHolder.Enabled = false;
                rfvIssuingBank.Enabled = false;
                rfvCardNo1.Enabled = false;
                revCardNo1.Enabled = false;
                rfvCardNo2.Enabled = false;
                revCardNo2.Enabled = false;
                rfvCardNo3.Enabled = false;
                revCardNo3.Enabled = false;
                rfvCardNo4.Enabled = false;
                revCardNo4.Enabled = false;
                rfvCardExpiryMonth.Enabled = false;
                rfvCardExpiryYear.Enabled = false;
                csvCCExpiredValid.Enabled = false;
                rfvCardType.Enabled = false;
                rfvCVV.Enabled = false;
                revCVV.Enabled = false;
            }
        }
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtCCExpiredValid.Text = "";
        txtCCExpiredValid.Text = "valid";
        Int32 _Year = Convert.ToInt32(ddlCardExpiryYear.Text);
        Int32 _Month = Convert.ToInt32(ddlCardExpiryMonth.Text);

        MySecurity _mysecurity = new MySecurity();
        if (_mysecurity.IsCreditCardExpiredDateValid(_Year, _Month))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }

    private void LoadCardExpiryMonth()
    {
        string _strmonth = "";
        for (int _month = 12; _month > 0; _month--)
        {
            _strmonth = _month.ToString();
            if (_month.ToString().Length < 2)
            {
                _strmonth = "0" + _month.ToString();
            }
            ddlCardExpiryMonth.Items.Insert(0, new ListItem(_strmonth, _strmonth));
        }
        ddlCardExpiryMonth.Items.Insert(0, new ListItem(Resources.CarInsurance.Month, "-1"));
    }

    private void LoadCardExpiryYear()
    {
        int _year;
        int startyear = dateTimeNow.Year;
        int endyear = dateTimeNow.Year + 10;
        for (_year = endyear; _year >= startyear; _year--)
        {
            ddlCardExpiryYear.Items.Insert(0, new ListItem(_year.ToString("0000"), _year.ToString("00")));
        }
        ddlCardExpiryYear.Items.Insert(0, new ListItem(Resources.CarInsurance.Year, "-1"));
    }

    private void ClearPayFields()
    {
        txtStatus.Text = "TRUE";
        btnPayDecline.Visible = false;
        grvPayment.Enabled = true;
        pnlPaymentInput.Visible = true;
        btnPaySubmit.Text = Resources.General.Submit;
        lblLoadMessage.Text = string.Empty;
        txtPaymentId.Text = "0";
        EnableDisable();
        lblPayError.Text = "";
        txtAmount.Text = "";
        ddlPaymentOption.SelectedIndex = 0;
        ddlPaymentOption_SelectedIndexChanged(null, null);
        ddlPaymentType.SelectedIndex = 0;
        ddlPaymentType_SelectedIndexChanged(null, null);
        txtCardHolder.Text = "";
        txtCardNo1.Text = "";
        txtCardNo2.Text = "";
        txtCardNo3.Text = "";
        txtCardNo4.Text = "";
        txtIssuingBank.Text = "";
        txtPaymentRefNo.Text = "";
        ddlCardExpiryMonth.SelectedIndex = 0;
        ddlCardExpiryYear.SelectedIndex = 0;
        ddlCardType.SelectedIndex = 0;
        txtCVV.Text = "000";
        chkRefund.Checked = false;
        chkApprove.Checked = false;
        chkRefund.Enabled = true;
        //Sakthi 14 Jun 2012 -Start
        chkApprove.Enabled = false;
        //Sakthi 14 Jun 2012 -End

        txtAmount.ReadOnly = false;
        divCC.Visible = false;
        rfvCVV.Enabled = true;
        revCVV.Enabled = true;
        
    }

    private bool ChackPayValidate()
    {
        bool _IsValid = true;
        if (rfvAmount.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revAmount.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvPaymentOption.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvPaymentType.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardHolder.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvIssuingBank.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardNo1.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revCardNo1.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardNo2.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revCardNo2.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardNo3.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revCardNo3.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardNo4.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revCardNo4.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardExpiryMonth.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardExpiryYear.IsValid == false)
        {
            _IsValid = false;
        }
        else if (csvCCExpiredValid.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCardType.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvCVV.IsValid == false)
        {
            _IsValid = false;
        }
        else if (revCVV.IsValid == false)
        {
            _IsValid = false;
        }
        else if (rfvPaymentRefNo.IsValid == false)
        {
            _IsValid = false;
        }
        return _IsValid;
    }

    public string GenerateNonGGExcel(Int64 CECarId, Int64 ProviderId, string FilePath, string FileName)
    {
        string _returnFilePath = "";
        Label lblContent = new Label();
        StringBuilder strText = new StringBuilder("");
        strText.Append("<table><tr><td colspan='2'><h3>ประกันภัยรถยนต์ - แบบฟอร์ม</h3></td></tr></table>");
        DataSet _dsApplication = new DataSet();
        NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
        _dsApplication = _nonggpackagedb.GetNonGGApplication(CECarId, ProviderId, 0);
        string _html = "";
        if (_dsApplication.Tables[0].Rows.Count > 0)
        {

            #region Variable Declaration

            string strSql = "";
            MyDatabase _db = new MyDatabase();
            string Title, Name, DOB, Gender, Occupation, ContactNo, Email, PresentAddress, SubDistrict, District, Province, PostalCode, Insurer, Package, NoOfDriver;
            string InsuranceType, GarageType, CarModelYear, CarMakeModel, Size, VehicleWeight, NumberofSeat, Beneficiary, VehicleType, SumInsured, NCB;
            string CurrentInsurer, CarPlate, CarPlateProvince, EngineNumber, ChassisNumber, Modification, AnyClaims, AddDrivers, CommencementDate;
            string Premium, CTPL, CTPLAmount, TotalPremium, PaymentType, QuoteRefNo, Payment, ApplicationDate, TotalCollectedPremium, CustomerName;
            string CustomerType, CTPLStart, ProviderPremium, strLastYearRefNo, strLastYearPolicyNo, strTitle;
           
            float _GrossPremium = 0.0f;

            strLastYearRefNo = string.Empty;
            strLastYearPolicyNo = string.Empty;
            Title = ""; Name = ""; DOB = ""; Gender = ""; Occupation = ""; ContactNo = ""; Email = ""; PresentAddress = ""; SubDistrict = ""; District = "";
            Province = ""; PostalCode = ""; Insurer = ""; Package = ""; NoOfDriver = ""; InsuranceType = ""; GarageType = ""; CarModelYear = "";
            CarMakeModel = ""; Size = ""; VehicleWeight = ""; NumberofSeat = ""; Beneficiary = ""; VehicleType = ""; SumInsured = ""; NCB = "";
            CurrentInsurer = ""; CarPlate = ""; CarPlateProvince = ""; EngineNumber = ""; ChassisNumber = ""; Modification = ""; AnyClaims = "";
            AddDrivers = ""; CommencementDate = ""; Premium = ""; CTPL = ""; CTPLAmount = ""; TotalPremium = ""; PaymentType = ""; CTPLStart = "";
            QuoteRefNo = ""; Payment = ""; ApplicationDate = ""; TotalCollectedPremium = ""; CustomerName = ""; CustomerType = ""; ProviderPremium = "";
            //For Driver
            string DriverName1, DriverDOB1, DriverName2, DriverDOB2, Driver1LicenseNo, Driver2LicenseNo, Driver1IDNo, Driver2IDNo;
            DriverName1 = ""; DriverDOB1 = ""; DriverName2 = ""; DriverDOB2 = ""; Driver1LicenseNo = ""; Driver2LicenseNo = "";
            Driver1IDNo = ""; Driver2IDNo = "";

            #endregion

            #region Assign Values
            strTitle = "รายละเอียดผู้ทำประกัน";
            if (ddlApplicationType.Text == "REN")
            {
                strTitle += " - ต่ออายุ";
            }
            else if (ddlApplicationType.Text == "CHB")
            {
                strTitle += " - เปลี่ยนโบรกเกอร์";
            }
            if (lblLastYearRefNo.Text != string.Empty && lblLastYearRefNo.Text != "0" && txtCarId.Text != string.Empty && txtCarId.Text != "0")
            {
                
                strLastYearRefNo = lblLastYearRefNo.Text;
                strSql = "SELECT Info2 FROM tblNonGGCarMoreDetails WHERE Info2 IS NOT NULL AND LEN(Info2) > 0 AND CECarId = " + txtCarId.Text.Trim() + " AND RefCEUserId = " + txtUserId.Text.Trim();
                DataTable _SelectItemResult = _db.GetDataTable(strSql);
                if (_SelectItemResult != null && _SelectItemResult.Rows.Count > 0)
                {
                    if (_SelectItemResult.Rows[0]["Info2"] != DBNull.Value)
                    {
                        strLastYearPolicyNo = _SelectItemResult.Rows[0]["Info2"].ToString();
                    }
                }
            }
            else
            {
                strLastYearRefNo = lblLastYearRefNo.Text;
            }
            Email = _dsApplication.Tables[0].Rows[0]["Email"].ToString();
            Title = _dsApplication.Tables[0].Rows[0]["Title"].ToString();
            Name = _dsApplication.Tables[0].Rows[0]["Name"].ToString();
            CustomerName = _dsApplication.Tables[0].Rows[0]["CustomerName"].ToString();
            CustomerType = _dsApplication.Tables[0].Rows[0]["CustomerTypeTH"].ToString();
            DOB = _dsApplication.Tables[0].Rows[0]["DOB"].ToString();
            Gender = _dsApplication.Tables[0].Rows[0]["Gender"].ToString();
            Occupation = _dsApplication.Tables[0].Rows[0]["Occupation"].ToString();
            ContactNo = _dsApplication.Tables[0].Rows[0]["ContactNo"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            PresentAddress = _dsApplication.Tables[0].Rows[0]["PresentAddress"].ToString();
            SubDistrict = _dsApplication.Tables[0].Rows[0]["SubDistrict"].ToString();
            District = _dsApplication.Tables[0].Rows[0]["District"].ToString();
            Province = _dsApplication.Tables[0].Rows[0]["Province"].ToString();
            PostalCode = _dsApplication.Tables[0].Rows[0]["PostalCode"].ToString();
            Insurer = _dsApplication.Tables[0].Rows[0]["CompanyName"].ToString();
            Package = _dsApplication.Tables[0].Rows[0]["Package"].ToString();
            NoOfDriver = _dsApplication.Tables[0].Rows[0]["NoOfDriver"].ToString();
            if (NoOfDriver.ToString() == "0")
            {
                AddDrivers = "No";
            }
            else
            {
                AddDrivers = "Yes";
            }
            InsuranceType = _dsApplication.Tables[0].Rows[0]["InsuranceType"].ToString();
            GarageType = _dsApplication.Tables[0].Rows[0]["GarageType"].ToString();
            CarModelYear = _dsApplication.Tables[0].Rows[0]["CarModelYear"].ToString();
            CarMakeModel = _dsApplication.Tables[0].Rows[0]["CarMakeModel"].ToString();
           
            EngineNumber = _dsApplication.Tables[0].Rows[0]["EngineNumber"].ToString();
            ChassisNumber = _dsApplication.Tables[0].Rows[0]["ChassisNumber"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            VehicleType = _dsApplication.Tables[0].Rows[0]["VehicleType"].ToString();
            SumInsured = _dsApplication.Tables[0].Rows[0]["SumInsured"].ToString();
            NCB = _dsApplication.Tables[0].Rows[0]["NCB"].ToString();
            CurrentInsurer = _dsApplication.Tables[0].Rows[0]["CurrentInsurer"].ToString();
            CarPlate = _dsApplication.Tables[0].Rows[0]["CarPlate"].ToString();
            CarPlateProvince = _dsApplication.Tables[0].Rows[0]["ProvinceRegistration"].ToString();
            
            CommencementDate = _dsApplication.Tables[0].Rows[0]["CommencementDate"].ToString();
            Premium = _dsApplication.Tables[0].Rows[0]["Premium"].ToString();

            CTPL = _dsApplication.Tables[0].Rows[0]["CTPL"].ToString();
            CTPLAmount = _dsApplication.Tables[0].Rows[0]["CTPLAmount"].ToString();
            CTPLStart = _dsApplication.Tables[0].Rows[0]["CTPLStart"].ToString();
            TotalPremium = _dsApplication.Tables[0].Rows[0]["TotalPremium"].ToString();
            TotalCollectedPremium = _dsApplication.Tables[0].Rows[0]["TotalCollectedPremium"].ToString();
            PaymentType = _dsApplication.Tables[0].Rows[0]["PaymentType"].ToString();
            QuoteRefNo = _dsApplication.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            Payment = _dsApplication.Tables[0].Rows[0]["Payment"].ToString();
            ApplicationDate = _dsApplication.Tables[0].Rows[0]["ApplicationDate"].ToString();
            
            if (_dsApplication.Tables[0].Rows[0]["GrossPremium"] != DBNull.Value && _dsApplication.Tables[0].Rows[0]["GrossPremium"].ToString() != string.Empty)
            {
                _GrossPremium = Convert.ToSingle(_dsApplication.Tables[0].Rows[0]["GrossPremium"].ToString());
            }
            ProviderPremium = GetProviderPremium(_GrossPremium, CTPL.ToUpper(), CTPLAmount);

            if (AddDrivers == "Yes")
            {
                if (_dsApplication.Tables[1].Rows.Count > 0)
                {
                    if (Convert.ToInt16(NoOfDriver) > 0)
                    {
                        DriverName1 = _dsApplication.Tables[1].Rows[0]["FullName"].ToString();
                        DriverDOB1 = _dsApplication.Tables[1].Rows[0]["DOB"].ToString();
                        Driver1IDNo = _dsApplication.Tables[1].Rows[0]["IDNo"].ToString();
                        Driver1LicenseNo = _dsApplication.Tables[1].Rows[0]["DrivingLicenseNumber"].ToString();
                    }
                    if (Convert.ToInt16(NoOfDriver) > 1)
                    {

                        DriverName2 = _dsApplication.Tables[1].Rows[1]["FullName"].ToString();
                        DriverDOB2 = _dsApplication.Tables[1].Rows[1]["DOB"].ToString();
                        Driver2IDNo = _dsApplication.Tables[1].Rows[1]["IDNo"].ToString();
                        Driver2LicenseNo = _dsApplication.Tables[1].Rows[1]["DrivingLicenseNumber"].ToString();
                    }
                }
            }

            #endregion

            #region Generate Excel File
            _html += "<html><body><table width='60%' cellpadding='1' cellspacing='1' border='1'>";
            if (ddlApplicationType.Text == "REN")
            {
                _html += "<tr><td width='20%' align='left' colspan='2'><b>" + strTitle + "</b></td></tr>";
                _html += "<tr><td width='300' align='left'><b>เลขที่อ้างอิงปีที่แล้ว</b></td><td  align='left'>" + strLastYearRefNo.ToString() + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>เลขที่กรมธรรม์ปีที่แล้ว</b></td><td  align='left'>" + strLastYearPolicyNo.ToString() + "</td></tr>";
            }
            else if (ddlApplicationType.Text == "CHB")
            {
                _html += "<tr><td width='20%' align='left' colspan='2'><b>" + strTitle + "</b></td></tr>";
                _html += "<tr><td width='300' align='left'><b>เลขที่กรมธรรม์ปีที่แล้ว</b></td><td  align='left'>" + strLastYearPolicyNo.ToString() + "</td></tr>";
            }
            else
            {
                _html += "<tr><td width='20%' align='left' colspan='2'><b>รายละเอียดผู้ทำประกัน</b></td></tr>";
            }

            _html += "<tr><td width='300' align='left'><b>ประเภทลูกค้า</b></td><td  align='left'>" + CustomerType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>คำนำหน้า</b></td><td  align='left'>" + Title + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ชื่อผู้ทำประกัน</b></td><td  align='left'>" + Name + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>วันเกิด</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + DOB + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เพศ</b></td><td  align='left'>" + Gender + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>อาชีพ</b></td><td  align='left'>" + Occupation + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เบอร์ติดต่อ</b></td><td style='mso-number-format:\\@' align='left'>" + ContactNo + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ที่อยู่ปัจจุบัน</b></td><td  align='left'>" + PresentAddress + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>แขวง/ตำบล</b></td><td  align='left'>" + SubDistrict + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เขต/อำเภอ</b></td><td  align='left'>" + District + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>จังหวัด</b></td><td  align='left'>" + Province + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>รหัสไปรษณีย์</b></td><td  align='left'>" + PostalCode + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>บริษัทประกัน</b></td><td  align='left'>" + Insurer + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>แพกเก็จ</b></td><td  align='left'>" + Package + "</td></tr>";

            _html += "<tr><td width='300' align='left'><b>ระบุผู้ขับขี่</b></td><td  align='left'>" + AddDrivers + "</td></tr>";
            if (AddDrivers == "Yes")
            {
                _html += "<tr><td width='300' align='left'><b>จำนวนผู้ขับขี่</b></td><td  align='left'>" + NoOfDriver + "</td></tr>";
            }
            if (Convert.ToInt16(NoOfDriver) > 0)
            {
                _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 1</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB1 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1</b></td><td  align='left'>" + DriverName1 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver1IDNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่ใบขับขี่</b></td><td  align='left'>" + Driver1LicenseNo + "</td></tr>";
            }
            if (Convert.ToInt16(NoOfDriver) > 1)
            {
                _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 2</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB2 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2</b></td><td  align='left'>" + DriverName2 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver2IDNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่ใบขับข</b></td><td  align='left'>" + Driver2LicenseNo + "</td></tr>";
            }
            _html += "<tr><td width='300' align='left'><b>ประเภทประกัน</b></td><td  align='left'>" + InsuranceType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ประเภทอู่</b></td><td  align='left'>" + GarageType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ปีของรถ</b></td><td  align='left'>" + CarModelYear + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>รุ่น</b></td><td  align='left'>" + CarMakeModel + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ผู้รับผลประโยชน์</b></td><td  align='left'>" + Beneficiary + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ประเภทรถ</b></td><td  align='left'>" + VehicleType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ทุนประกัน</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + SumInsured + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ส่วนลด NCB</b></td><td  align='left'>" + NCB + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>บริษัทประกันปัจจุบัน</b></td><td  align='left'>" + CurrentInsurer + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ทะเบียนรถ</b></td><td  align='left'>" + CarPlate + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>จังหวัดที่จดทะเบียน</b></td><td  align='left'>" + CarPlateProvince + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>หมายเลขเครื่อง</b></td><td  align='left'>" + EngineNumber + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>หมายเลข Chassis</b></td><td  align='left'>" + ChassisNumber + "</td></tr>";
            _html += "<tr><td width='300'  align='left'><b>วันเริ่มคุ้มครอง (ภาคสมัครใจ)</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + CommencementDate + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เบี้ยประกันภาคสมัครใจ</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + _GrossPremium.ToString() + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ซื้อ พ.ร.บ. หรือไม่</b></td><td  align='left'>" + CTPL + "</td></tr>";
            if (CTPL == "Yes")
            {
                _html += "<tr><td width='300' align='left'><b>เบี้ย พ.ร.บ.</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + CTPLAmount + "</td></tr>";
            }
            else
            {
                _html += "<tr><td width='300' align='left'><b>เบี้ย พ.ร.บ.</b></td><td align='left'>-</td></tr>";
            }
            _html += "<tr><td width='300'  align='left'><b>วันที่ พ.ร.บ.เริ่มคุ้มครอง</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + CTPLStart + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เบี้ยประกันรวมทั้งหมด</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + ProviderPremium + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>วันที่ทำรายการ</b></td><td align='left'>ตาม วัน/เวลา ที่ปรากฎในอีเมล์</td></tr>";

            _html += "</table></body></html>";
            #endregion

            lblContent.Text = _html;
            MyIO myio = new MyIO();

            string[] filecontent = new string[1];
            filecontent[0] = lblContent.Text.ToString();

            myio.WriteNewFile(FilePath, FileName + ".xls", filecontent);
            _returnFilePath = FilePath + FileName + ".xls";
        }
        return _returnFilePath;
    }

    public Int16 AmountExceedValid(Int16 Process)
    {
        string i = txtTotalRefundAmount.Text;
        Int16 _IsValid = 1;
        float Premium = 0;
        float Collected = 0;
        float Amount = 0;
        float Refund = 0;
        float Balance = 0;
        if (lblUpPremium.Text != "")
            Premium = Convert.ToSingle(lblUpPremium.Text);
        if (txtTotalCollectedAmount.Text != "")
            Collected = Convert.ToSingle(txtTotalCollectedAmount.Text);
        if (txtAmount.Text != "")
            Amount = Convert.ToSingle(txtAmount.Text);
        if (txtTotalRefundAmount.Text != "")
            Refund = Convert.ToSingle(txtTotalRefundAmount.Text);
        if (txtBalanceAmount.Text != "")
            Balance = Convert.ToSingle(txtBalanceAmount.Text);
        if (Process == 1)
        {
            if (chkApprove.Checked == false)
            {
                if (chkRefund.Checked)
                {
                    
                    if (Collected < (Amount))
                    {
                        _IsValid = 2;
                    }
                }
                else
                {
                    float _calAmount = (Collected - Refund) + Amount;
                   
                    if (Premium < _calAmount)
                    {
                        _IsValid = 3;
                    }
                    else if (Amount > Balance)
                    {
                        _IsValid = 3;
                    }


                    if (Premium == _calAmount)
                    {
                        _IsValid = 1;
                    }

                }
            }
        }
        if (Process == 2)
        {
            _IsValid = 0;
            DataSet _dsPaymentAmount = new DataSet();
            _dsPaymentAmount = GetPaymentAmounts();
            if (_dsPaymentAmount != null && _dsPaymentAmount.Tables.Count > 0 && _dsPaymentAmount.Tables[0].Rows.Count > 0)
            {
                Premium = 0;
                Collected = 0;
                if (_dsPaymentAmount.Tables[0].Rows[0]["PremiumAmount"].ToString() != null && _dsPaymentAmount.Tables[0].Rows[0]["PremiumAmount"].ToString() != "")
                    Premium = Convert.ToSingle(_dsPaymentAmount.Tables[0].Rows[0]["PremiumAmount"].ToString());
                if (_dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString() != null && _dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString() != "")
                    Collected = Convert.ToSingle(_dsPaymentAmount.Tables[0].Rows[0]["CollectedAmount"].ToString());
                if (Premium > 0 && Premium == Collected)
                {
                    _IsValid = 1;
                }
            }
        }
        if (Process == 3)
        {
            if (txtOnlineAmount.Text != "")
            {
                Amount = Convert.ToSingle(txtOnlineAmount.Text);
            }

            float _calAmount = (Collected - Refund) + Amount;

            
            if (Premium < _calAmount)
            {
                _IsValid = 4;
            }
            else if (Amount > Balance)
            {
                _IsValid = 4;
            }

        }
        return _IsValid;
    }

    public DataSet GetTransaction(string QuoteRefNo, Int16 TransactionTypeId)
    {
        DataSet _dsTransaction = new DataSet();
        TransactionDB _transactiondb = new TransactionDB();
        _dsTransaction = _transactiondb.GetTransaction(QuoteRefNo, TransactionTypeId);
        return _dsTransaction;
    }

    public bool SubmitPaymentPermission()
    {
        bool _Valid = true;
        if (txtPaymentId.Text != "" && txtPaymentId.Text != "0" && chkApprove.Checked && Session[CE.Global.General.UserRole] != null && Session[CE.Global.General.UserRole].ToString() != "300")
        {
            _Valid = false;
        }
        if (lblMailingStatus.Text != string.Empty && lblMailingStatus.Text == "1")
        {
            _Valid = false;
        }
        return _Valid;
    }

    public string GetColor(string ApproveType)
    {
        string color = "red";
        if (ApproveType == "1")
        {
            color = "green";
        }
        return color;
    }

    public void EnableDisable()
    {
        bool Enable = true;
        if (txtPaymentId.Text != string.Empty && Convert.ToInt64(txtPaymentId.Text.Trim()) > 0)
        {
            Enable = false;
        }
        ddlPaymentType.Enabled = Enable;
        ddlPaymentOption.Enabled = Enable;
        txtCardHolder.Enabled = Enable;
        txtIssuingBank.Enabled = Enable;
        txtCardNo1.Enabled = Enable;
        txtCardNo2.Enabled = Enable;
        txtCardNo3.Enabled = Enable;
        txtCardNo4.Enabled = Enable;
        ddlCardExpiryMonth.Enabled = Enable;
        ddlCardExpiryYear.Enabled = Enable;
        ddlCardType.Enabled = Enable;
        txtCVV.Enabled = Enable;

    }

    public bool SendApproveMailToAdmin(Int16 TransactionType, string CustomerName, string Amount, string BrokerEmail, Int16 Status)
    {
        bool _result = true;
        string mailBody = "";
        string _emailTitle = "";
        string _toemail = "";
        string _ccemail = "";
        string _bccemail = "";
        _emailTitle = "[" + lblUpRefNo.Text + "] " + Resources.CarInsurance.Payment + "  [" + txtPlateNumber.Text + "]";
        mailBody = Resources.General.CustomerName + " : " + CustomerName + "<br/><br/>";
        mailBody += Resources.CarInsurance.Amount + " : " + Amount + "<br/><br/>";
        if (TransactionType == 1)
        {
            mailBody += Resources.General.TransactionType + " : " + Resources.CarInsurance.Payment + "<br/><br/>";
        }
        else if (TransactionType == 2)
        {
            mailBody += Resources.General.TransactionType + " : " + Resources.CarInsurance.Refund + "<br/><br/>";
        }
        if (Status == 1)
        {
            mailBody += Resources.General.Status + " : <b style='color:green;'>" + Resources.CarInsurance.Approve + "</b><br/><br/>";
        }
        else if (Status == 0)
        {
            mailBody += Resources.General.Status + " : <b style='color:red;'>" + Resources.General.Decline + "</b><br/><br/>";
        }
        mailBody += Resources.General.DateTime + " : " + dateTimeNow.ToString("dd-MMM-yyyy hh:mm:ss tt") + "<br/><br/>";
        _toemail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("ADMIN");
        _toemail += BrokerEmail;
        _bccemail = "";

        if (Session[General.UserRole].ToString() == "100")
        {
            _ccemail += Session[General.SMTPReplyTo].ToString();
        }

       

        _result = MyMailManager.SendGGMail(ConfigurationManager.AppSettings["GGFormsSMTPAccount"].ToString(), ConfigurationManager.AppSettings["GGFormsSMTPAuthCode"].ToString(), _toemail, _ccemail, _bccemail, _emailTitle, mailBody, Session[General.SMTPReplyTo].ToString());

        return _result;
    }

    private string GetSMTPAccount(string smtpKey)
    {
        string _retValue = string.Empty;

        if (smtpKey == "admin")
        {
            _retValue = ConfigurationManager.AppSettings["ADMIN"].ToString();
        }
        else if (smtpKey == "cashier")
        {
            _retValue = ConfigurationManager.AppSettings["CASH"].ToString();
        }
        else if (smtpKey == "broker1")
        {
            _retValue = ConfigurationManager.AppSettings["Broker1ReplyTo"].ToString();
        }
        else if (smtpKey == "broker2")
        {
            _retValue = ConfigurationManager.AppSettings["Broker2ReplyTo"].ToString();
        }
        else if (smtpKey == "broker3")
        {
            _retValue = ConfigurationManager.AppSettings["Broker3ReplyTo"].ToString();
        }
        else if (smtpKey == "broker4")
        {
            _retValue = ConfigurationManager.AppSettings["Broker4ReplyTo"].ToString();
        }
        else if (smtpKey == "broker5")
        {
            _retValue = ConfigurationManager.AppSettings["Broker5ReplyTo"].ToString();
        }
        else if (smtpKey == "broker6")
        {
            _retValue = ConfigurationManager.AppSettings["Broker6ReplyTo"].ToString();
        }
        else if (smtpKey == "broker7")
        {
            _retValue = ConfigurationManager.AppSettings["Broker7ReplyTo"].ToString();
        }

        return _retValue;
    }

    private string GetProviderPremium(float NetPremium, float Discount, string CTPL, string CTPLAmount)
    {
        string _retValue = string.Empty;
        try
        {
            if (CTPL.ToString() == string.Empty)
            {
                CTPL = "NO";
            }
            if (CTPLAmount.ToString() == string.Empty)
            {
                CTPLAmount = "0";
            }
            decimal _netPremium = Convert.ToDecimal(NetPremium.ToString());

            decimal _tax = 0;
            _tax = Convert.ToDecimal(_netPremium * (0.4M / 100.0M));
            _tax = Convert.ToDecimal(_tax.ToString("#.00"));

            decimal _vat = 0;
            decimal _vatamt1 = 0;
            decimal _vatamt2 = 0;
            _vatamt1 = Convert.ToDecimal((_netPremium + _tax).ToString("#.00"));
            _vatamt2 = Convert.ToDecimal(7.0M / 100.0M);
            _vat = Convert.ToDecimal(_vatamt1 * _vatamt2);
            //_vat = Convert.ToDecimal((_netPremium + _tax) * Convert.ToDecimal(7.0M / 100.0M));
            _vat = Convert.ToDecimal(_vat.ToString("#.00"));


            decimal _annualPremium = 0;

            if (Discount > 0)
            {
                decimal _discountAmount = Convert.ToDecimal((_netPremium * Convert.ToDecimal(Convert.ToDecimal(Discount) / 100.0M)));
                _annualPremium = _netPremium - _discountAmount;
                _annualPremium = _annualPremium + _vat + Math.Ceiling(_tax); ;
            }
            else
            {
                _annualPremium = _netPremium + _vat + Math.Ceiling(_tax);
            }

            if (CTPL == "YES")
            {
                _annualPremium = _annualPremium + Math.Ceiling(Convert.ToDecimal(CTPLAmount.ToString()));
            }
            _retValue = _annualPremium.ToString("#.00");
        }
        catch (Exception Ex)
        {
            Ex = null;
        }

        return _retValue;
    }

    private string GetProviderPremium(float GrossPremium, string CTPL, string CTPLAmount)
    {
        string _retValue = string.Empty;
        try
        {
            if (CTPL.ToString() == string.Empty)
            {
                CTPL = "NO";
            }
            if (CTPLAmount.ToString() == string.Empty)
            {
                CTPLAmount = "0";
            }
            decimal _grossPremium = Convert.ToDecimal(GrossPremium.ToString());
            if (CTPL == "YES")
            {
                _grossPremium = _grossPremium + Convert.ToDecimal(CTPLAmount.ToString());
            }
            _retValue = _grossPremium.ToString("#.00");
        }
        catch (Exception Ex)
        {
            Ex = null;
        }

        return _retValue;
    }

    #region Not Using - 10 Jul 2012

    public string GenerateNonGGExcel(Int64 CECarId, Int64 ProviderId, string Language)
    {
        DataSet _dsApplication = new DataSet();
        NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
        _dsApplication = _nonggpackagedb.GetNonGGApplication(CECarId, ProviderId, 1);
        string _html = "";
        if (_dsApplication.Tables[0].Rows.Count > 0)
        {

            #region Variable Declaration

            string Title, Name, DOB, Gender, Occupation, ContactNo, Email, PresentAddress, SubDistrict, District, Province, PostalCode, Insurer, Package, NoOfDriver;
            string InsuranceType, GarageType, CarModelYear, CarMakeModel, Size, VehicleWeight, NumberofSeat, Beneficiary, VehicleType, SumInsured, NCB;
            string CurrentInsurer, CarPlate, CarPlateProvince, EngineNumber, ChassisNumber, Modification, AnyClaims, AddDrivers, CommencementDate;
            string Premium, CTPL, CTPLAmount, TotalPremium, PaymentType, QuoteRefNo, Payment, ApplicationDate;

            Title = ""; Name = ""; DOB = ""; Gender = ""; Occupation = ""; ContactNo = ""; Email = ""; PresentAddress = ""; SubDistrict = ""; District = "";
            Province = ""; PostalCode = ""; Insurer = ""; Package = ""; NoOfDriver = ""; InsuranceType = ""; GarageType = ""; CarModelYear = "";
            CarMakeModel = ""; Size = ""; VehicleWeight = ""; NumberofSeat = ""; Beneficiary = ""; VehicleType = ""; SumInsured = ""; NCB = "";
            CurrentInsurer = ""; CarPlate = ""; CarPlateProvince = ""; EngineNumber = ""; ChassisNumber = ""; Modification = ""; AnyClaims = "";
            AddDrivers = ""; CommencementDate = ""; Premium = ""; CTPL = ""; CTPLAmount = ""; TotalPremium = ""; PaymentType = "";
            QuoteRefNo = ""; Payment = ""; ApplicationDate = "";
            //For Driver
            string DriverName1, DriverDOB1, DriverName2, DriverDOB2, Driver1LicenseNo, Driver2LicenseNo, Driver1IDNo, Driver2IDNo;
            DriverName1 = ""; DriverDOB1 = ""; DriverName2 = ""; DriverDOB2 = ""; Driver1LicenseNo = ""; Driver2LicenseNo = "";
            Driver1IDNo = ""; Driver2IDNo = "";

            #endregion

            #region Assign Values

            Email = _dsApplication.Tables[0].Rows[0]["Email"].ToString();
            Title = _dsApplication.Tables[0].Rows[0]["Title"].ToString();
            Name = _dsApplication.Tables[0].Rows[0]["Name"].ToString();
            DOB = _dsApplication.Tables[0].Rows[0]["DOB"].ToString();
            Gender = _dsApplication.Tables[0].Rows[0]["Gender"].ToString();
            Occupation = _dsApplication.Tables[0].Rows[0]["Occupation"].ToString();
            ContactNo = _dsApplication.Tables[0].Rows[0]["ContactNo"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            PresentAddress = _dsApplication.Tables[0].Rows[0]["PresentAddress"].ToString();
            SubDistrict = _dsApplication.Tables[0].Rows[0]["SubDistrict"].ToString();
            District = _dsApplication.Tables[0].Rows[0]["District"].ToString();
            Province = _dsApplication.Tables[0].Rows[0]["Province"].ToString();
            PostalCode = _dsApplication.Tables[0].Rows[0]["PostalCode"].ToString();
            Insurer = _dsApplication.Tables[0].Rows[0]["CompanyName"].ToString();
            Package = _dsApplication.Tables[0].Rows[0]["Package"].ToString();
            NoOfDriver = _dsApplication.Tables[0].Rows[0]["NoOfDriver"].ToString();
            if (NoOfDriver.ToString() == "0")
            {
                AddDrivers = "No";
            }
            else
            {
                AddDrivers = "Yes";
            }
            InsuranceType = _dsApplication.Tables[0].Rows[0]["InsuranceType"].ToString();
            GarageType = _dsApplication.Tables[0].Rows[0]["GarageType"].ToString();
            CarModelYear = _dsApplication.Tables[0].Rows[0]["CarModelYear"].ToString();
            CarMakeModel = _dsApplication.Tables[0].Rows[0]["CarMakeModel"].ToString();
            Size = _dsApplication.Tables[0].Rows[0]["Size"].ToString();
            VehicleWeight = _dsApplication.Tables[0].Rows[0]["VehicleWeight"].ToString();
            NumberofSeat = _dsApplication.Tables[0].Rows[0]["NumberofSeat"].ToString();
            EngineNumber = _dsApplication.Tables[0].Rows[0]["EngineNumber"].ToString();
            ChassisNumber = _dsApplication.Tables[0].Rows[0]["ChassisNumber"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            VehicleType = _dsApplication.Tables[0].Rows[0]["VehicleType"].ToString();
            SumInsured = _dsApplication.Tables[0].Rows[0]["SumInsured"].ToString();
            NCB = _dsApplication.Tables[0].Rows[0]["NCB"].ToString();
            CurrentInsurer = _dsApplication.Tables[0].Rows[0]["CurrentInsurer"].ToString();
            CarPlate = _dsApplication.Tables[0].Rows[0]["CarPlate"].ToString();
            CarPlateProvince = _dsApplication.Tables[0].Rows[0]["ProvinceRegistration"].ToString();
            Modification = _dsApplication.Tables[0].Rows[0]["Accessories"].ToString();
            AnyClaims = _dsApplication.Tables[0].Rows[0]["AnyClaims"].ToString();
            CommencementDate = _dsApplication.Tables[0].Rows[0]["CommencementDate"].ToString();
            Premium = _dsApplication.Tables[0].Rows[0]["Premium"].ToString();

            CTPL = _dsApplication.Tables[0].Rows[0]["CTPL"].ToString();
            CTPLAmount = _dsApplication.Tables[0].Rows[0]["CTPLAmount"].ToString();
            TotalPremium = _dsApplication.Tables[0].Rows[0]["TotalPremium"].ToString();
            PaymentType = _dsApplication.Tables[0].Rows[0]["PaymentType"].ToString();
            QuoteRefNo = _dsApplication.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            Payment = _dsApplication.Tables[0].Rows[0]["Payment"].ToString();
            ApplicationDate = _dsApplication.Tables[0].Rows[0]["OrderDate"].ToString();

            if (AddDrivers == "Yes")
            {
                if (_dsApplication.Tables[1].Rows.Count > 0)
                {
                    if (Convert.ToInt16(NoOfDriver) > 0)
                    {
                        DriverName1 = _dsApplication.Tables[1].Rows[0]["FullName"].ToString();
                        DriverDOB1 = _dsApplication.Tables[1].Rows[0]["DOB"].ToString();
                        Driver1IDNo = _dsApplication.Tables[1].Rows[0]["IDNo"].ToString();
                        Driver1LicenseNo = _dsApplication.Tables[1].Rows[0]["DrivingLicenseNumber"].ToString();
                    }
                    if (Convert.ToInt16(NoOfDriver) > 1)
                    {

                        DriverName2 = _dsApplication.Tables[1].Rows[1]["FullName"].ToString();
                        DriverDOB2 = _dsApplication.Tables[1].Rows[1]["DOB"].ToString();
                        Driver2IDNo = _dsApplication.Tables[1].Rows[1]["IDNo"].ToString();
                        Driver2LicenseNo = _dsApplication.Tables[1].Rows[1]["DrivingLicenseNumber"].ToString();
                    }
                }
            }

            #endregion

            #region Generate Excel File
            if (Language == "EN")
            {
                _html += "<html><body><table width='60%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='2'><b>Applicant Details</b></td></tr>";
                _html += "<tr><td width='300' align='left'><b>Prefix</b></td><td align='left'>" + Title + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Applicant Name</b></td><td align='left'>" + Name + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>DOB</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DOB + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Gender</b></td><td align='left'>" + Gender + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Occupation</b></td><td align='left'>" + Occupation + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ContactNo</b></td><td style='mso-number-format:\\@' align='left'>" + ContactNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>PresentAddress</b></td><td align='left'>" + PresentAddress + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>SubDistrict</b></td><td align='left'>" + SubDistrict + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>District</b></td><td align='left'>" + District + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Province</b></td><td align='left'>" + Province + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>PostalCode</b></td><td align='left'>" + PostalCode + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Insurer</b></td><td align='left'>" + Insurer + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Package</b></td><td align='left'>" + Package + "</td></tr>";

                _html += "<tr><td width='300' align='left'><b>Specify Named Driver</b></td><td align='left'>" + AddDrivers + "</td></tr>";
                if (AddDrivers == "Yes")
                {
                    _html += "<tr><td width='300' align='left'><b>Number Of Named Driver</b></td><td align='left'>" + NoOfDriver + "</td></tr>";
                }
                if (Convert.ToInt16(NoOfDriver) > 0)
                {
                    _html += "<tr><td width='300' align='left'><b>DOB of 1st Driver</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB1 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>Name of 1st Driver</b></td><td align='left'>" + DriverName1 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>First Driver's ID No.</b></td><td style='mso-number-format:\\@' align='left'>" + Driver1IDNo + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>First Driver's License No.</b></td><td  align='left'>" + Driver1LicenseNo + "</td></tr>";
                }
                if (Convert.ToInt16(NoOfDriver) > 1)
                {
                    _html += "<tr><td width='300' align='left'><b>DOB of 2nd Driver</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB2 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>Nameof 2nd Driver</b></td><td align='left'>" + DriverName2 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>Second Driver's ID No.</b></td><td style='mso-number-format:\\@' align='left'>" + Driver2IDNo + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>Second Driver's License No.</b></td><td  align='left'>" + Driver2LicenseNo + "</td></tr>";
                }

                _html += "<tr><td width='300' align='left'><b>InsuranceType</b></td><td align='left'>" + InsuranceType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>GarageType</b></td><td align='left'>" + GarageType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>CarModelYear</b></td><td align='left'>" + CarModelYear + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>CarMakeModel</b></td><td align='left'>" + CarMakeModel + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Size (cc.)</b></td><td align='left'>" + Size + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Gross Vehicle Weight (kgs)</b></td><td align='left'>" + VehicleWeight + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Number of seat</b></td><td align='left'>" + NumberofSeat + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Beneficiary</b></td><td align='left'>" + Beneficiary + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>VehicleType</b></td><td align='left'>" + VehicleType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>SumInsured</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + SumInsured + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>NCB</b></td><td align='left'>" + NCB + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>CurrentInsurer</b></td><td align='left'>" + CurrentInsurer + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Car Plate</b></td><td align='left'>" + CarPlate + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Car Plate Province</b></td><td align='left'>" + CarPlateProvince + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>EngineNumber</b></td><td align='left'>" + EngineNumber + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ChassisNumber</b></td><td align='left'>" + ChassisNumber + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Added Accessories Or Modifications?</b></td><td align='left'>" + Modification + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Any Claim in Last Year?</b></td><td align='left'>" + AnyClaims + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>The insurance coverage Starts</b></td><td align='left'style='mso-number-format:dd\\-MM\\-yyyy'>" + CommencementDate + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>Voluntary Insurance Premium</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + Premium + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>CTPL</b></td><td align='left'>" + CTPL + "</td></tr>";
                if (CTPL == "Yes")
                {
                    _html += "<tr><td width='300' align='left'><b>CTPL Amount</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + CTPLAmount + "</td></tr>";
                }
                _html += "<tr><td width='300' align='left'><b>Total Premium</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + TotalPremium + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ApplicationDate</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy\\ hh\\:mm\\ AM\\/PM' align='left'>" + ApplicationDate + "</td></tr>";

                _html += "</table></body></html>";
            }
            else if (Language == "TH")
            {
                _html += "<html><body><table width='60%' cellpadding='1' cellspacing='1' border='1'>";
                _html += "<tr><td align='left' colspan='2'><b>รายละเอียดผู้ทำประกัน</b></td></tr>";
                _html += "<tr><td width='300' align='left'><b>คำนำหน้า</b></td><td  align='left'>" + Title + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ชื่อผู้ทำประกัน</b></td><td  align='left'>" + Name + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>วันเกิด</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + DOB + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>เพศ</b></td><td  align='left'>" + Gender + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>อาชีพ</b></td><td  align='left'>" + Occupation + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>เบอร์ติดต่อ</b></td><td style='mso-number-format:\\@' align='left'>" + ContactNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ที่อยู่ปัจจุบัน</b></td><td  align='left'>" + PresentAddress + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>แขวง/ตำบล</b></td><td  align='left'>" + SubDistrict + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>เขต/อำเภอ</b></td><td  align='left'>" + District + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>จังหวัด</b></td><td  align='left'>" + Province + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>รหัสไปรษณีย์</b></td><td  align='left'>" + PostalCode + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>บริษัทประกัน</b></td><td  align='left'>" + Insurer + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>แพกเก็จ</b></td><td  align='left'>" + Package + "</td></tr>";

                _html += "<tr><td width='300' align='left'><b>ระบุผู้ขับขี่</b></td><td  align='left'>" + AddDrivers + "</td></tr>";
                if (AddDrivers == "Yes")
                {
                    _html += "<tr><td width='300' align='left'><b>จำนวนผู้ขับขี่</b></td><td  align='left'>" + NoOfDriver + "</td></tr>";
                }
                if (Convert.ToInt16(NoOfDriver) > 0)
                {
                    _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 1</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB1 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1</b></td><td  align='left'>" + DriverName1 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver1IDNo + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่ใบขับขี่</b></td><td  align='left'>" + Driver1LicenseNo + "</td></tr>";
                }
                if (Convert.ToInt16(NoOfDriver) > 1)
                {
                    _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 2</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB2 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2</b></td><td  align='left'>" + DriverName2 + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver2IDNo + "</td></tr>";
                    _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่ใบขับขี่</b></td><td  align='left'>" + Driver2LicenseNo + "</td></tr>";
                }
                _html += "<tr><td width='300' align='left'><b>ประเภทประกัน</b></td><td  align='left'>" + InsuranceType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ประเภทอู่</b></td><td  align='left'>" + GarageType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ปีของรถ</b></td><td  align='left'>" + CarModelYear + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>รุ่น</b></td><td  align='left'>" + CarMakeModel + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ขนาด (cc.)</b></td><td  align='left'>" + Size + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>น้ำหนักรถ (kgs)</b></td><td align='left'>" + VehicleWeight + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>จำนวนที่นั่ง</b></td><td  align='left'>" + NumberofSeat + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้รับผลประโยชน์</b></td><td  align='left'>" + Beneficiary + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ประเภทรถ</b></td><td  align='left'>" + VehicleType + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ทุนประกัน</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + SumInsured + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ส่วนลด NCB</b></td><td  align='left'>" + NCB + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>บริษัทประกันปัจจุบัน</b></td><td  align='left'>" + CurrentInsurer + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ทะเบียนรถ</b></td><td  align='left'>" + CarPlate + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>จังหวัดที่จดทะเบียน</b></td><td  align='left'>" + CarPlateProvince + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>หมายเลขเครื่อง</b></td><td  align='left'>" + EngineNumber + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>หมายเลข Chassis</b></td><td  align='left'>" + ChassisNumber + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>มีอุปกรณ์พิเศษ?</b></td><td  align='left'>" + Modification + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>มีการเคลมปีที่แล้วหรือไม่?</b></td><td>" + AnyClaims + "</td></tr>";
                _html += "<tr><td width='300'  align='left'><b>วันที่เริ่มทำประกัน</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + CommencementDate + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>เบี้ยประกันภาคสมัครใจ</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + Premium + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>พ.ร.บ.</b></td><td  align='left'>" + CTPL + "</td></tr>";
                if (CTPL == "Yes")
                {
                    _html += "<tr><td width='300' align='left'><b>จำนวน (พ.ร.บ.)</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + CTPLAmount + "</td></tr>";
                }
                _html += "<tr><td width='300' align='left'><b>ราคารวม</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + TotalPremium + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>วันที่ทำรายการ</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy\\ hh\\:mm\\ AM\\/PM'  align='left'>" + ApplicationDate + "</td></tr>";

                _html += "</table></body></html>";
            }
            #endregion
        }
        return _html;
    }

    public string GenerateNonGGExcelInternal(Int64 CECarId, Int64 ProviderId, string FilePath, string FileName)
    {
        string _returnFilePath = "";
        Label lblContent = new Label();
        StringBuilder strText = new StringBuilder("");
        strText.Append("<table><tr><td colspan='2'><h3>ประกันภัยรถยนต์ - แบบฟอร์ม</h3></td></tr></table>");
        DataSet _dsApplication = new DataSet();
        NonGGPackageDB _nonggpackagedb = new NonGGPackageDB();
        _dsApplication = _nonggpackagedb.GetNonGGApplication(CECarId, ProviderId, 0);
        string _html = "";
        if (_dsApplication.Tables[0].Rows.Count > 0)
        {

            #region Variable Declaration

            string Title, Name, DOB, Gender, Occupation, ContactNo, Email, PresentAddress, SubDistrict, District, Province, PostalCode, Insurer, Package, NoOfDriver;
            string InsuranceType, GarageType, CarModelYear, CarMakeModel, Size, VehicleWeight, NumberofSeat, Beneficiary, VehicleType, SumInsured, NCB;
            string CurrentInsurer, CarPlate, CarPlateProvince, EngineNumber, ChassisNumber, Modification, AnyClaims, AddDrivers, CommencementDate;
            string Premium, CTPL, CTPLAmount, TotalPremium, PaymentType, QuoteRefNo, Payment, ApplicationDate;

            Title = ""; Name = ""; DOB = ""; Gender = ""; Occupation = ""; ContactNo = ""; Email = ""; PresentAddress = ""; SubDistrict = ""; District = "";
            Province = ""; PostalCode = ""; Insurer = ""; Package = ""; NoOfDriver = ""; InsuranceType = ""; GarageType = ""; CarModelYear = "";
            CarMakeModel = ""; Size = ""; VehicleWeight = ""; NumberofSeat = ""; Beneficiary = ""; VehicleType = ""; SumInsured = ""; NCB = "";
            CurrentInsurer = ""; CarPlate = ""; CarPlateProvince = ""; EngineNumber = ""; ChassisNumber = ""; Modification = ""; AnyClaims = "";
            AddDrivers = ""; CommencementDate = ""; Premium = ""; CTPL = ""; CTPLAmount = ""; TotalPremium = ""; PaymentType = "";
            QuoteRefNo = ""; Payment = ""; ApplicationDate = "";
            //For Driver
            string DriverName1, DriverDOB1, DriverName2, DriverDOB2, Driver1LicenseNo, Driver2LicenseNo, Driver1IDNo, Driver2IDNo;
            DriverName1 = ""; DriverDOB1 = ""; DriverName2 = ""; DriverDOB2 = ""; Driver1LicenseNo = ""; Driver2LicenseNo = "";
            Driver1IDNo = ""; Driver2IDNo = "";

            #endregion

            #region Assign Values

            Email = _dsApplication.Tables[0].Rows[0]["Email"].ToString();
            Title = _dsApplication.Tables[0].Rows[0]["Title"].ToString();
            Name = _dsApplication.Tables[0].Rows[0]["Name"].ToString();
            DOB = _dsApplication.Tables[0].Rows[0]["DOB"].ToString();
            Gender = _dsApplication.Tables[0].Rows[0]["Gender"].ToString();
            Occupation = _dsApplication.Tables[0].Rows[0]["Occupation"].ToString();
            ContactNo = _dsApplication.Tables[0].Rows[0]["ContactNo"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            PresentAddress = _dsApplication.Tables[0].Rows[0]["PresentAddress"].ToString();
            SubDistrict = _dsApplication.Tables[0].Rows[0]["SubDistrict"].ToString();
            District = _dsApplication.Tables[0].Rows[0]["District"].ToString();
            Province = _dsApplication.Tables[0].Rows[0]["Province"].ToString();
            PostalCode = _dsApplication.Tables[0].Rows[0]["PostalCode"].ToString();
            Insurer = _dsApplication.Tables[0].Rows[0]["CompanyName"].ToString();
            Package = _dsApplication.Tables[0].Rows[0]["Package"].ToString();
            NoOfDriver = _dsApplication.Tables[0].Rows[0]["NoOfDriver"].ToString();
            if (NoOfDriver.ToString() == "0")
            {
                AddDrivers = "No";
            }
            else
            {
                AddDrivers = "Yes";
            }
            InsuranceType = _dsApplication.Tables[0].Rows[0]["InsuranceType"].ToString();
            GarageType = _dsApplication.Tables[0].Rows[0]["GarageType"].ToString();
            CarModelYear = _dsApplication.Tables[0].Rows[0]["CarModelYear"].ToString();
            CarMakeModel = _dsApplication.Tables[0].Rows[0]["CarMakeModel"].ToString();
            Size = _dsApplication.Tables[0].Rows[0]["Size"].ToString();
            VehicleWeight = _dsApplication.Tables[0].Rows[0]["VehicleWeight"].ToString();
            NumberofSeat = _dsApplication.Tables[0].Rows[0]["NumberofSeat"].ToString();
            EngineNumber = _dsApplication.Tables[0].Rows[0]["EngineNumber"].ToString();
            ChassisNumber = _dsApplication.Tables[0].Rows[0]["ChassisNumber"].ToString();
            Beneficiary = _dsApplication.Tables[0].Rows[0]["Beneficiary"].ToString();
            VehicleType = _dsApplication.Tables[0].Rows[0]["VehicleType"].ToString();
            SumInsured = _dsApplication.Tables[0].Rows[0]["SumInsured"].ToString();
            NCB = _dsApplication.Tables[0].Rows[0]["NCB"].ToString();
            CurrentInsurer = _dsApplication.Tables[0].Rows[0]["CurrentInsurer"].ToString();
            CarPlate = _dsApplication.Tables[0].Rows[0]["CarPlate"].ToString();
            CarPlateProvince = _dsApplication.Tables[0].Rows[0]["ProvinceRegistration"].ToString();
            Modification = _dsApplication.Tables[0].Rows[0]["Accessories"].ToString();
            AnyClaims = _dsApplication.Tables[0].Rows[0]["AnyClaims"].ToString();
            CommencementDate = _dsApplication.Tables[0].Rows[0]["CommencementDate"].ToString();
            Premium = _dsApplication.Tables[0].Rows[0]["Premium"].ToString();

            CTPL = _dsApplication.Tables[0].Rows[0]["CTPL"].ToString();
            CTPLAmount = _dsApplication.Tables[0].Rows[0]["CTPLAmount"].ToString();
            TotalPremium = _dsApplication.Tables[0].Rows[0]["TotalPremium"].ToString();
            PaymentType = _dsApplication.Tables[0].Rows[0]["PaymentType"].ToString();
            QuoteRefNo = _dsApplication.Tables[0].Rows[0]["QuoteRefNo"].ToString();
            Payment = _dsApplication.Tables[0].Rows[0]["Payment"].ToString();
            ApplicationDate = _dsApplication.Tables[0].Rows[0]["OrderDate"].ToString();

            if (AddDrivers == "Yes")
            {
                if (_dsApplication.Tables[1].Rows.Count > 0)
                {
                    if (Convert.ToInt16(NoOfDriver) > 0)
                    {
                        DriverName1 = _dsApplication.Tables[1].Rows[0]["FullName"].ToString();
                        DriverDOB1 = _dsApplication.Tables[1].Rows[0]["DOB"].ToString();
                        Driver1IDNo = _dsApplication.Tables[1].Rows[0]["IDNo"].ToString();
                        Driver1LicenseNo = _dsApplication.Tables[1].Rows[0]["DrivingLicenseNumber"].ToString();
                    }
                    if (Convert.ToInt16(NoOfDriver) > 1)
                    {

                        DriverName2 = _dsApplication.Tables[1].Rows[1]["FullName"].ToString();
                        DriverDOB2 = _dsApplication.Tables[1].Rows[1]["DOB"].ToString();
                        Driver2IDNo = _dsApplication.Tables[1].Rows[1]["IDNo"].ToString();
                        Driver2LicenseNo = _dsApplication.Tables[1].Rows[1]["DrivingLicenseNumber"].ToString();
                    }
                }
            }

            #endregion

            #region Generate Excel File
            _html += "<html><body><table width='60%' cellpadding='1' cellspacing='1' border='1'>";
            _html += "<tr><td width='20%' align='left' colspan='2'><b>รายละเอียดผู้ทำประกัน</b></td></tr>";
            _html += "<tr><td width='300' align='left'><b>คำนำหน้า</b></td><td  align='left'>" + Title + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ชื่อผู้ทำประกัน</b></td><td  align='left'>" + Name + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>วันเกิด</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + DOB + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เพศ</b></td><td  align='left'>" + Gender + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>อาชีพ</b></td><td  align='left'>" + Occupation + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เบอร์ติดต่อ</b></td><td style='mso-number-format:\\@' align='left'>" + ContactNo + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ที่อยู่ปัจจุบัน</b></td><td  align='left'>" + PresentAddress + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>แขวง/ตำบล</b></td><td  align='left'>" + SubDistrict + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เขต/อำเภอ</b></td><td  align='left'>" + District + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>จังหวัด</b></td><td  align='left'>" + Province + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>รหัสไปรษณีย์</b></td><td  align='left'>" + PostalCode + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>บริษัทประกัน</b></td><td  align='left'>" + Insurer + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>แพกเก็จ</b></td><td  align='left'>" + Package + "</td></tr>";

            _html += "<tr><td width='300' align='left'><b>ระบุผู้ขับขี่</b></td><td  align='left'>" + AddDrivers + "</td></tr>";
            if (AddDrivers == "Yes")
            {
                _html += "<tr><td width='300' align='left'><b>จำนวนผู้ขับขี่</b></td><td  align='left'>" + NoOfDriver + "</td></tr>";
            }
            if (Convert.ToInt16(NoOfDriver) > 0)
            {
                _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 1</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB1 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1</b></td><td  align='left'>" + DriverName1 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver1IDNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 1 เลขที่ใบขับขี่</b></td><td  align='left'>" + Driver1LicenseNo + "</td></tr>";
            }
            if (Convert.ToInt16(NoOfDriver) > 1)
            {
                _html += "<tr><td width='300' align='left'><b>วันเกิด ผู้ขับขี่คนที่ 2</b></td><td  style='mso-number-format:dd\\-mmm\\-yyyy' align='left'>" + DriverDOB2 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2</b></td><td  align='left'>" + DriverName2 + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่บัตรประชาชน</b></td><td style='mso-number-format:\\@' align='left'>" + Driver2IDNo + "</td></tr>";
                _html += "<tr><td width='300' align='left'><b>ผู้ขับขี่คนที่ 2 เลขที่ใบขับข</b></td><td  align='left'>" + Driver2LicenseNo + "</td></tr>";
            }
            _html += "<tr><td width='300' align='left'><b>ประเภทประกัน</b></td><td  align='left'>" + InsuranceType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ประเภทอู่</b></td><td  align='left'>" + GarageType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ปีของรถ</b></td><td  align='left'>" + CarModelYear + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>รุ่น</b></td><td  align='left'>" + CarMakeModel + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ขนาด (cc.)</b></td><td  align='left'>" + Size + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>น้ำหนักรถ (kgs)</b></td><td align='left'>" + VehicleWeight + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>จำนวนที่นั่ง</b></td><td  align='left'>" + NumberofSeat + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ผู้รับผลประโยชน์</b></td><td  align='left'>" + Beneficiary + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ประเภทรถ</b></td><td  align='left'>" + VehicleType + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ทุนประกัน</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + SumInsured + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ส่วนลด NCB</b></td><td  align='left'>" + NCB + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>บริษัทประกันปัจจุบัน</b></td><td  align='left'>" + CurrentInsurer + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>ทะเบียนรถ</b></td><td  align='left'>" + CarPlate + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>จังหวัดที่จดทะเบียน</b></td><td  align='left'>" + CarPlateProvince + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>หมายเลขเครื่อง</b></td><td  align='left'>" + EngineNumber + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>หมายเลข Chassis</b></td><td  align='left'>" + ChassisNumber + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>มีอุปกรณ์พิเศษ?</b></td><td  align='left'>" + Modification + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>มีการเคลมปีที่แล้วหรือไม่?</b></td><td>" + AnyClaims + "</td></tr>";
            _html += "<tr><td width='300'  align='left'><b>วันที่เริ่มทำประกัน</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy'  align='left'>" + CommencementDate + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>เบี้ยประกันภาคสมัครใจ</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00' align='left'>" + Premium + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>พ.ร.บ.</b></td><td  align='left'>" + CTPL + "</td></tr>";
            if (CTPL == "Yes")
            {
                _html += "<tr><td width='300' align='left'><b>จำนวน (พ.ร.บ.)</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + CTPLAmount + "</td></tr>";
            }
            _html += "<tr><td width='300' align='left'><b>ราคารวม</b></td><td style='mso-number-format:\\#\\,\\#\\#0\\.00'  align='left'>" + TotalPremium + "</td></tr>";
            _html += "<tr><td width='300' align='left'><b>วันที่ทำรายการ</b></td><td style='mso-number-format:dd\\-mmm\\-yyyy\\ hh\\:mm\\ AM\\/PM'  align='left'>" + ApplicationDate + "</td></tr>";

            _html += "</table></body></html>";
            #endregion

            lblContent.Text = _html;
            MyIO myio = new MyIO();

            string[] filecontent = new string[1];
            filecontent[0] = lblContent.Text.ToString();

            myio.WriteNewFile(FilePath, FileName + ".xls", filecontent);
            _returnFilePath = FilePath + FileName + ".xls";
        }
        return _returnFilePath;
    }

    private string GetQuoteRefNoByProvider(Int64 _ProviderId, Int64 CarID)
    {
        string QuoteRefNo = "";
        string convertno = General.GetRefNumber(CarID);
        if (_ProviderId == 11)
        {
            QuoteRefNo = "AZC" + convertno.ToString();
        }
        else if (_ProviderId == 12)
        {
            QuoteRefNo = "MSI" + convertno.ToString();
        }
        else if (_ProviderId == 16)
        {
            QuoteRefNo = "AXA" + convertno.ToString();
        }
        else if (_ProviderId == 29)
        {
            QuoteRefNo = "LMG" + convertno.ToString();
        }
        else if (_ProviderId == 31)
        {
            QuoteRefNo = "CTS" + convertno.ToString();
        }
        else if (_ProviderId == 32)
        {
            QuoteRefNo = "BKI" + convertno.ToString();
        }
        else if (_ProviderId == 33)
        {
            QuoteRefNo = "MTI" + convertno.ToString();
        }
        else if (_ProviderId == 41)
        {
            QuoteRefNo = "KUR" + convertno.ToString();
        }
        else if (_ProviderId == 46)
        {
            QuoteRefNo = "TMS" + convertno.ToString();
        }
        else if (_ProviderId == 35)
        {
            QuoteRefNo = "KPI" + convertno.ToString();
        }
        return QuoteRefNo;
    }

    public string GetReferenceNumber(string Number, string ProviderId)
    {
        string convertno = CE.Global.General.GetRefNumber(Convert.ToInt64(Number.ToString()));
        string _RefNo = "";
        if (ProviderId == "11")
        {
            _RefNo = "AZC" + convertno.ToString();
        }
        else if (ProviderId == "12")
        {
            _RefNo = "MSI" + convertno.ToString();
        }
        else if (ProviderId == "16")
        {
            _RefNo = "AXA" + convertno.ToString();
        }
        else if (ProviderId == "29")
        {
            _RefNo = "LMG" + convertno.ToString();
        }
        else if (ProviderId == "31")
        {
            _RefNo = "CTS" + convertno.ToString();
        }
        else if (ProviderId == "32")
        {
            _RefNo = "BKI" + convertno.ToString();
        }
        else if (ProviderId == "33")
        {
            _RefNo = "MTI" + convertno.ToString();
        }
        else if (ProviderId == "41")
        {
            _RefNo = "KUR" + convertno.ToString();
        }
        else if (ProviderId == "46")
        {
            _RefNo = "TMS" + convertno.ToString();
        }
        else if (ProviderId == "35")
        {
            _RefNo = "KPI" + convertno.ToString();
        }
        return _RefNo;
    }

    private string GetProviderName(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "อลิอันซ์ ซี.พี. ประกันภัย";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "เอ็ม เอส ไอ จี ประกันภัย";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "แอกซ่า ประกันภัย";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "แอลเอ็มจี ประกันภัย";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "กรุงเทพประกันภัย";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "เมืองไทยประกันภัย";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "คูเนีย ประกันภัย";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "โตเกียวมารีนศรีเมือง";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "กรุงไทยพานิชประกันภัย";
        }
        return _result;
    }

    private string GetProviderName(Int64 ProviderCompanyId, string Language)
    {
        string _result = "";
        if (Language == "1")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "อลิอันซ์ ซี.พี. ประกันภัย";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "เอ็ม เอส ไอ จี ประกันภัย";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "แอกซ่า ประกันภัย";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "แอลเอ็มจี ประกันภัย";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "นิวแฮมพ์เชอร์ อินชัวรันส์";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "กรุงเทพประกันภัย";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "เมืองไทยประกันภัย";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "คูเนีย ประกันภัย";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "โตเกียวมารีนศรีเมือง";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "กรุงไทยพานิชประกันภัย";
            }
        }
        else if (Language == "2")
        {
            if (ProviderCompanyId == 11)
            {
                _result = "Allianz CP Insurance";
            }
            else if (ProviderCompanyId == 12)
            {
                _result = "MSIG Insurance";
            }
            else if (ProviderCompanyId == 16)
            {
                _result = "AXA Insurance";
            }
            else if (ProviderCompanyId == 29)
            {
                _result = "LMG  Insurance";
            }
            else if (ProviderCompanyId == 31)
            {
                _result = "Chartis Insurance";
            }
            else if (ProviderCompanyId == 32)
            {
                _result = "BKI Insurance";
            }
            else if (ProviderCompanyId == 33)
            {
                _result = "MuangThai Insurance";
            }
            else if (ProviderCompanyId == 41)
            {
                _result = "Kurnia Insurance";
            }
            else if (ProviderCompanyId == 46)
            {
                _result = "Tokio Marine Insurance";
            }
            else if (ProviderCompanyId == 35)
            {
                _result = "KrungThai Insurance";
            }
        }
        return _result;
    }

    private string GetProviderBrokerCode(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "001600";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "AFM1012";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "BB115";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "BR00619";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "002851000";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "641100";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "74000352";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "198700-00";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "10233002";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "-/207";
        }
        return _result;
    }

    private string GetProviderMail(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "TO_AZCP";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "TO_MSIG";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "TO_AXA";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "TO_LMG";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "TO_CTS";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "TO_BKI";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "TO_MTI";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "TO_KUR";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "TO_TMS";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "TO_KPI";
        }
        return _result;
    }

    private string GetProvider(Int64 ProviderCompanyId)
    {
        string _result = "";
        if (ProviderCompanyId == 11)
        {
            _result = "azcp";
        }
        else if (ProviderCompanyId == 12)
        {
            _result = "msig";
        }
        else if (ProviderCompanyId == 16)
        {
            _result = "axa";
        }
        else if (ProviderCompanyId == 29)
        {
            _result = "lmg";
        }
        else if (ProviderCompanyId == 31)
        {
            _result = "cts";
        }
        else if (ProviderCompanyId == 32)
        {
            _result = "bki";
        }
        else if (ProviderCompanyId == 33)
        {
            _result = "mti";
        }
        else if (ProviderCompanyId == 41)
        {
            _result = "kur";
        }
        else if (ProviderCompanyId == 46)
        {
            _result = "tms";
        }
        else if (ProviderCompanyId == 35)
        {
            _result = "kpi";
        }
        return _result;
    }

    private string GetProviderId(string Provider)
    {
        string _result = "0";
        if (Provider.ToUpper() == "AZC")
        {
            _result = "11";
        }
        else if (Provider.ToUpper() == "MSI")
        {
            _result = "12";
        }
        else if (Provider.ToUpper() == "AXA")
        {
            _result = "16";
        }
        else if (Provider.ToUpper() == "LMG")
        {
            _result = "29";
        }
        else if (Provider.ToUpper() == "CTS")
        {
            _result = "31";
        }
        else if (Provider.ToUpper() == "BKI")
        {
            _result = "32";
        }
        else if (Provider.ToUpper() == "MTI")
        {
            _result = "33";
        }
        else if (Provider.ToUpper() == "KUR")
        {
            _result = "41";
        }
        else if (Provider.ToUpper() == "TMS")
        {
            _result = "46";
        }
        else if (Provider.ToUpper() == "KPI")
        {
            _result = "35";
        }
        return _result;
    }

    #endregion
}
